问:
How to set selenium/standalone-chrome timeout?
My goal is to kill the remote session if there is something wrong the other container that is connected to selenium. The problem is, I can't change the timeout to immediately terminate session.

What I've did:

use SE_NODE_SESSION_TIMEOUT docker run -d -p 4444:4444 -m=300m -e SE_NODE_SESSION_TIMEOUT=1 seleniarm/standalone-chromium:4.1.2-20220227

The code, I run this in a ipynb file. If I reload the code cell, it won't connect and checking at http://127.0.0.1:4444 shows that there is still a session.

```<code>
from selenium import webdriver
from selenium.webdriver.common.by import By

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--disable-notifications")
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')

driver = webdriver.Remote(options=chrome_options)
</code>```

EDIT: Docker said the session-timeout has been set to 1

```<code>[node]
session-timeout = "1"
override-max-sessions = false
detect-drivers = false
max-sessions = 1
</code>```

However, when I tried to reload the driver, it won't let me because it still think there is 1 active session.

Body:
My goal is to kill the remote session if there is something wrong the other container that is connected to selenium. The problem is, I can't change the timeout to immediately terminate session.

What I've did:

use SE_NODE_SESSION_TIMEOUT docker run -d -p 4444:4444 -m=300m -e SE_NODE_SESSION_TIMEOUT=1 seleniarm/standalone-chromium:4.1.2-20220227

The code, I run this in a ipynb file. If I reload the code cell, it won't connect and checking at http://127.0.0.1:4444 shows that there is still a session.

from selenium import webdriver
from selenium.webdriver.common.by import By

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--disable-notifications")
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')

driver = webdriver.Remote(options=chrome_options)

EDIT: Docker said the session-timeout has been set to 1

[node]
session-timeout = "1"
override-max-sessions = false
detect-drivers = false
max-sessions = 1

However, when I tried to reload the driver, it won't let me because it still think there is 1 active session.


来源: stackexchange

问:
Random Communications link failure errors when connecting to RDS mysql from EKS Fargate cluster pods
I'm trying to establish connectivity between a pod running on EKS Fargate cluster and an RDS based MySQL. I can see the pod fails with the following error multiple times before it can eventually connect ( sometimes it takes 2/3 restarts, and sometimes it just does not start at all):

```55887 [main] ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
        at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
        at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
        at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364)
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476)
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
        at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
        at com.acxiom.cloud.core.config.MySQLConfig.jndiDataSource(MySQLConfig.java:40)
        at com.acxiom.cloud.core.config.MySQLConfig$$EnhancerBySpringCGLIB$$45bc0623.CGLIB$jndiDataSource$0(<generated>)
        at com.acxiom.cloud.core.config.MySQLConfig$$EnhancerBySpringCGLIB$$45bc0623$$FastClassBySpringCGLIB$$5fc079e4.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
        at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
        atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:212)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:203)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:97)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:86)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:262)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:236)
        at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:430)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486)
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123)
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104)
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:479)
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:184)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
        at com.acxiom.cloud.core.CoreApplication.main(CoreApplication.java:17)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
        at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
        at com.mysql.cj.protocol.a.NativeProtocol.afterHandshake(NativeProtocol.java:450)
        at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:539)
        at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:212)
        at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1433)
        at com.mysql.cj.NativeSession.connect(NativeSession.java:133)
        at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:948)
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:818)
        ... 132 common frames omitted
Caused by: java.net.SocketException: Connection attempt exceeded defined timeout.
        at com.mysql.cj.protocol.StandardSocketFactory.resetLoginTimeCountdown(StandardSocketFactory.java:212)
        at com.mysql.cj.protocol.StandardSocketFactory.afterHandshake(StandardSocketFactory.java:197)
        at com.mysql.cj.protocol.a.NativeProtocol.afterHandshake(NativeProtocol.java:448)
        ... 138 common frames omitted
55894 [main] ERROR o.s.b.w.e.tomcat.TomcatStarter - Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfiguration.class]: Initialization of bean failed;org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiDataSource' defined in class path resource [com/acxiom/cloud/core/config/MySQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'jndiDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
56495 [main] INFO  o.a.catalina.core.StandardService - Stopping service [Tomcat]
56601 [main] WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
56786 [main] INFO  o.s.b.a.l.ConditionEvaluationReportLoggingListener -

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
57100 [main] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:165)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142)
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104)
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:479)
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:184)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162)
        ... 16 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourcePoolMetadataMeterBinder' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration$DataSourcePoolMetadataMetricsConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourcePoolMetadataMeterBinder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiDataSource' defined in class path resource [com/acxiom/cloud/core/config/MySQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'jndiDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541)
        atorg.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:97)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:86)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:262)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:236)
        at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5211)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1383)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1383)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:265)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:430)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486)
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123)
        ... 21 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourcePoolMetadataMeterBinder' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration$DataSourcePoolMetadataMetricsConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourcePoolMetadataMeterBinder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiDataSource' defined in class path resource [com/acxiom/cloud/core/config/MySQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'jndiDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:628)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
        at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
        ... 61 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourcePoolMetadataMeterBinder' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration$DataSourcePoolMetadataMetricsConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourcePoolMetadataMeterBinder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiDataSource' defined in class path resource [com/acxiom/cloud/core/config/MySQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'jndiDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiDataSource' defined in class path resource [com/acxiom/cloud/core/config/MySQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'jndiDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
        ... 93 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'jndiDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
        ... 110 common frames omitted
Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
        at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
        at com.mysql.cj.protocol.a.NativeProtocol.afterHandshake(NativeProtocol.java:450)
        at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:539)
        at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:212)
        at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1433)
        at com.mysql.cj.NativeSession.connect(NativeSession.java:133)
        at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:948)
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:818)
        ... 132 common frames omitted
Caused by: java.net.SocketException: Connection attempt exceeded defined timeout.
        at com.mysql.cj.protocol.StandardSocketFactory.resetLoginTimeCountdown(StandardSocketFactory.java:212)
        at com.mysql.cj.protocol.StandardSocketFactory.afterHandshake(StandardSocketFactory.java:197)
        at com.mysql.cj.protocol.a.NativeProtocol.afterHandshake(NativeProtocol.java:448)
        ... 138 common frames omitted
```

I am using VPC peering between RDS and EKS VPCs (also tried with both on one VPC - with same results).

I attached the peering to the route tables on both RDS and EKS subnets (both public and private ones) pods are running on private subnets.

I made sure the CIDR of VPC of the cluster is attached to RDS security group on port 3306 (also tried on all TCP traffic).

I made sure VPC CNI plugin is installed on my cluster.

I added a security group policy (allowing eks cluster default sg & my dedicated eks pods sg) to the namespace where the pod is running.

I can connect to RDS using nc rds-external-name-service 3306 from busybox container on the same cluster.

I can connect to RDS using bastion host pod running on the same cluster
The pod usually succeeds in making the connection after a couple of restarts (but not always).

I tried setting up same configuration on EKS using managed nodes instead of Fargate and everything works smoothly.

ContentLicense: CC BY-SA 4.0

Body:
I'm trying to establish connectivity between a pod running on EKS Fargate cluster and an RDS based MySQL. I can see the pod fails with the following error multiple times before it can eventually connect ( sometimes it takes 2/3 restarts, and sometimes it just does not start at all):

55887 [main] ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
        at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
        at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
        at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364)
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476)
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
        at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
        at com.acxiom.cloud.core.config.MySQLConfig.jndiDataSource(MySQLConfig.java:40)
        at com.acxiom.cloud.core.config.MySQLConfig$$EnhancerBySpringCGLIB$$45bc0623.CGLIB$jndiDataSource$0(<generated>)
        at com.acxiom.cloud.core.config.MySQLConfig$$EnhancerBySpringCGLIB$$45bc0623$$FastClassBySpringCGLIB$$5fc079e4.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
        at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
        atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:212)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:203)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:97)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:86)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:262)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:236)
        at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:430)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486)
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123)
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104)
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:479)
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:184)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
        at com.acxiom.cloud.core.CoreApplication.main(CoreApplication.java:17)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
        at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
        at com.mysql.cj.protocol.a.NativeProtocol.afterHandshake(NativeProtocol.java:450)
        at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:539)
        at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:212)
        at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1433)
        at com.mysql.cj.NativeSession.connect(NativeSession.java:133)
        at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:948)
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:818)
        ... 132 common frames omitted
Caused by: java.net.SocketException: Connection attempt exceeded defined timeout.
        at com.mysql.cj.protocol.StandardSocketFactory.resetLoginTimeCountdown(StandardSocketFactory.java:212)
        at com.mysql.cj.protocol.StandardSocketFactory.afterHandshake(StandardSocketFactory.java:197)
        at com.mysql.cj.protocol.a.NativeProtocol.afterHandshake(NativeProtocol.java:448)
        ... 138 common frames omitted
55894 [main] ERROR o.s.b.w.e.tomcat.TomcatStarter - Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfiguration.class]: Initialization of bean failed;org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiDataSource' defined in class path resource [com/acxiom/cloud/core/config/MySQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'jndiDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
56495 [main] INFO  o.a.catalina.core.StandardService - Stopping service [Tomcat]
56601 [main] WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
56786 [main] INFO  o.s.b.a.l.ConditionEvaluationReportLoggingListener -

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
57100 [main] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:165)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142)
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104)
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:479)
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:184)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162)
        ... 16 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourcePoolMetadataMeterBinder' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration$DataSourcePoolMetadataMetricsConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourcePoolMetadataMeterBinder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiDataSource' defined in class path resource [com/acxiom/cloud/core/config/MySQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'jndiDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541)
        atorg.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:97)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:86)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:262)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:236)
        at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5211)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1383)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1383)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:265)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:430)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486)
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123)
        ... 21 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourcePoolMetadataMeterBinder' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration$DataSourcePoolMetadataMetricsConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourcePoolMetadataMeterBinder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiDataSource' defined in class path resource [com/acxiom/cloud/core/config/MySQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'jndiDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:628)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
        at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
        ... 61 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourcePoolMetadataMeterBinder' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration$DataSourcePoolMetadataMetricsConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourcePoolMetadataMeterBinder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiDataSource' defined in class path resource [com/acxiom/cloud/core/config/MySQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'jndiDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiDataSource' defined in class path resource [com/acxiom/cloud/core/config/MySQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'jndiDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
        ... 93 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'jndiDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
        ... 110 common frames omitted
Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
        at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
        at com.mysql.cj.protocol.a.NativeProtocol.afterHandshake(NativeProtocol.java:450)
        at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:539)
        at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:212)
        at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1433)
        at com.mysql.cj.NativeSession.connect(NativeSession.java:133)
        at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:948)
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:818)
        ... 132 common frames omitted
Caused by: java.net.SocketException: Connection attempt exceeded defined timeout.
        at com.mysql.cj.protocol.StandardSocketFactory.resetLoginTimeCountdown(StandardSocketFactory.java:212)
        at com.mysql.cj.protocol.StandardSocketFactory.afterHandshake(StandardSocketFactory.java:197)
        at com.mysql.cj.protocol.a.NativeProtocol.afterHandshake(NativeProtocol.java:448)
        ... 138 common frames omitted

I am using VPC peering between RDS and EKS VPCs (also tried with both on one VPC - with same results).

I attached the peering to the route tables on both RDS and EKS subnets (both public and private ones) pods are running on private subnets.

I made sure the CIDR of VPC of the cluster is attached to RDS security group on port 3306 (also tried on all TCP traffic).

I made sure VPC CNI plugin is installed on my cluster.

I added a security group policy (allowing eks cluster default sg & my dedicated eks pods sg) to the namespace where the pod is running.

I can connect to RDS using nc rds-external-name-service 3306 from busybox container on the same cluster.

I can connect to RDS using bastion host pod running on the same cluster
The pod usually succeeds in making the connection after a couple of restarts (but not always).

I tried setting up same configuration on EKS using managed nodes instead of Fargate and everything works smoothly.


问:
Retaining aspect ratio and scale iframe for parent div width defined in percentage
I have an issue where i need to use google ads as iframes that sit nicely at max-width in Zurb Foundation. However the ads are set out of my control and I need to find a way of scaling the Ads iframe width and height to 100% of the parent div and maintain aspect ratio of each ad.

Example mark-up of what happens before the google adwords js is triggered would be:

```<code><div class="cell resp" id="GA-ID-#####"><script>Google ads stuff in here</script></div>
</code>```

I can't use the padding hack, as I wont know the aspect ratio.

Google brings me nothing thats feasible; does anyone have experience of this?

Body:
I have an issue where i need to use google ads as iframes that sit nicely at max-width in Zurb Foundation. However the ads are set out of my control and I need to find a way of scaling the Ads iframe width and height to 100% of the parent div and maintain aspect ratio of each ad.

Example mark-up of what happens before the google adwords js is triggered would be:

I can't use the padding hack, as I wont know the aspect ratio.

Google brings me nothing thats feasible; does anyone have experience of this?


问:
How can I stop images from overlapping on gif with FuncAnimation in MatPlotLib?
I am trying to make a simple gif in Python with FuncAnimation of a bunch of arrows on a plot. I need the background of the plot to be transparent.

This is what I tried:

```<code>fig,ax = plt.subplots()

def update(num):
    plt.clf()
    ax.clear()
    plt.arrow(x=10, y=num, dx=num, dy=5, width=.08)
    plt.xlim(0,20)
    plt.ylim(0,20)
    plt.axis('off')
    plt.title('test')
    plt.rcParams.update({
    "figure.facecolor":  (0.0, 0.0, 0.0, 0),
    "axes.facecolor":    (0.0, 0.0, 0.0, 0),
    "savefig.facecolor": (0.0, 0.0, 0.0, 0),
    })

ani = FuncAnimation(fig, update, frames=range(10), repeat=False)
ani.save(path + 'test.gif', writer='pillow', fps=2)
</code>```

When I run this, I get the gif that I want, but the images are stacked in the gif each frame (one arrow gets added each frame, e.g. on frame 10 I'll see 10 arrows but I only want one at a time):

Overlapping Arrows

Adding this parameter to the ani.save function yields the same issue:

```<code>savefig_kwargs = {'transparent': True}
</code>```

Body:
I am trying to make a simple gif in Python with FuncAnimation of a bunch of arrows on a plot. I need the background of the plot to be transparent.

This is what I tried:

fig,ax = plt.subplots()

def update(num):
    plt.clf()
    ax.clear()
    plt.arrow(x=10, y=num, dx=num, dy=5, width=.08)
    plt.xlim(0,20)
    plt.ylim(0,20)
    plt.axis('off')
    plt.title('test')
    plt.rcParams.update({
    "figure.facecolor":  (0.0, 0.0, 0.0, 0),
    "axes.facecolor":    (0.0, 0.0, 0.0, 0),
    "savefig.facecolor": (0.0, 0.0, 0.0, 0),
    })

ani = FuncAnimation(fig, update, frames=range(10), repeat=False)
ani.save(path + 'test.gif', writer='pillow', fps=2)

When I run this, I get the gif that I want, but the images are stacked in the gif each frame (one arrow gets added each frame, e.g. on frame 10 I'll see 10 arrows but I only want one at a time):

Overlapping Arrows

Adding this parameter to the ani.save function yields the same issue:

savefig_kwargs = {'transparent': True}


问:
How to make next song play once it is ended using Vue3 and Vuex Store
I want to implement a music player using Vue and the Vuex Store. I want that the next song starts playing when the current one ends. In normal js, I'd just use:

```<code>curr_track.addEventListener("ended", playNext)
</code>```

where playNext would be a function I defined inside the same main.js file. When using Vue js and Vuex store, however, I can't do it the same. Any suggestions? I tried to pass the mutations function playNext inside of my store, but it did not work. Also, when calling

```<code>state.curr_track.duration = track.duration
</code>```

I get the error:

Uncaught TypeError: Cannot set property duration of #<HTMLMediaElement> which has only a getter

How do I fix this? Thank you

The code is the following:

```<code>import { createStore } from 'vuex'

const store = createStore({
    state() {
        return {
            curr_track: null,
            track_list: null,
            isPlaying: false,
        }
    },

    mutations: {

        setTrackList(state, tracks) {
            state.track_list = tracks
        },
        /**
         * Load the track and play it
         * @param state - the state object
         * @param state - the state object
         */
        loadTrack(state, track) {
            if (state.isPlaying) {
                state.curr_track.pause()
            }

            // get track info
            state.curr_track = new Audio()
            state.curr_track.id = track.id
            state.curr_track.src = track.file
            state.curr_track.name = track.name
            state.curr_track.artists = track.artists

            // TODO: fix duration
            // state.curr_track.duration = track.duration
            state.curr_track.album_name = track.album.name
            state.curr_track.album_cover = track.album.img_cover
            state.curr_track.load()

            // play track
            this.commit('playTrack')
            // TODO FIX
            state.curr_track.addEventListener("ended", function() {
                // if (state.track_list == null) {
                //     alert('Please select a track first')
                //     return []
                // }
                // if (state.track_list[state.track_list.length - 1]['id'] == state.curr_track.id) {
                //     console.log('last track, go to first')
                //     this.commit('loadTrack', state.track_list[0])
                // } else {
                //     console.log('go to next track')
                //     let curr_idx = state.track_list.findIndex(track => track.id == state.curr_track.id)
                //     this.commit('loadTrack', state.track_list[curr_idx + 1])
                // }
            })
        },
        playTrack(state) {
            // play loaded track
            if (state.curr_track != null) {
                state.curr_track.play();
                state.isPlaying = true;
            } else {
                alert('Please select a track first')
            }

        },
        pauseTrack(state) {
            // Pause the loaded track
            state.curr_track.pause();
            state.isPlaying = false;
        },
        setVolume(state, value) {
            // Set the volume
            state.curr_track.volume = value
        },

        /**
         * Play the next track: if the current track is the last track in the track list, then load the first track in the
         * track list. Otherwise, load the next track in the track list
         * @param state - the state object
         */
        playNext(state) {
            if (state.track_list == null) {
                alert('Please select a track first')
                return []
            }
            if (state.track_list[state.track_list.length - 1]['id'] == state.curr_track.id) {
                console.log('last track, go to first')
                this.commit('loadTrack', state.track_list[0])
            } else {
                console.log('go to next track')
                let curr_idx = state.track_list.findIndex(track => track.id == state.curr_track.id)
                this.commit('loadTrack', state.track_list[curr_idx + 1])
            }
        },

        /**
         * Play the previous track: if the current track is the first track in the track list, then load the last track in the
         * track list. Otherwise, load the previous track in the track list
         * @param state - the state object
         */
        playPrevious(state) {
            if (state.track_list[0]['id'] == state.curr_track.id) {
                console.log('first track, got to last one')
                this.commit('loadTrack', state.track_list[state.track_list.length - 1])
            } else {
                console.log('go to previous track')
                let curr_idx = state.track_list.findIndex(track => track.id == state.curr_track.id)
                this.commit('loadTrack', state.track_list[curr_idx - 1])
            }
        }
    },
    getters: {
        getIsPlaying(state) {
            return state.isPlaying
        },
        getCurrTrack(state) {
            return state.curr_track
        }

    },
    actions: {

    }
})

export default store
</code>```

Body:
I want to implement a music player using Vue and the Vuex Store. I want that the next song starts playing when the current one ends. In normal js, I'd just use:

curr_track.addEventListener("ended", playNext)

where playNext would be a function I defined inside the same main.js file. When using Vue js and Vuex store, however, I can't do it the same. Any suggestions? I tried to pass the mutations function playNext inside of my store, but it did not work. Also, when calling

state.curr_track.duration = track.duration

I get the error:

Uncaught TypeError: Cannot set property duration of #<HTMLMediaElement> which has only a getter

How do I fix this? Thank you

The code is the following:

import { createStore } from 'vuex'

const store = createStore({
    state() {
        return {
            curr_track: null,
            track_list: null,
            isPlaying: false,
        }
    },

    mutations: {

        setTrackList(state, tracks) {
            state.track_list = tracks
        },
        /**
         * Load the track and play it
         * @param state - the state object
         * @param state - the state object
         */
        loadTrack(state, track) {
            if (state.isPlaying) {
                state.curr_track.pause()
            }

            // get track info
            state.curr_track = new Audio()
            state.curr_track.id = track.id
            state.curr_track.src = track.file
            state.curr_track.name = track.name
            state.curr_track.artists = track.artists

            // TODO: fix duration
            // state.curr_track.duration = track.duration
            state.curr_track.album_name = track.album.name
            state.curr_track.album_cover = track.album.img_cover
            state.curr_track.load()

            // play track
            this.commit('playTrack')
            // TODO FIX
            state.curr_track.addEventListener("ended", function() {
                // if (state.track_list == null) {
                //     alert('Please select a track first')
                //     return []
                // }
                // if (state.track_list[state.track_list.length - 1]['id'] == state.curr_track.id) {
                //     console.log('last track, go to first')
                //     this.commit('loadTrack', state.track_list[0])
                // } else {
                //     console.log('go to next track')
                //     let curr_idx = state.track_list.findIndex(track => track.id == state.curr_track.id)
                //     this.commit('loadTrack', state.track_list[curr_idx + 1])
                // }
            })
        },
        playTrack(state) {
            // play loaded track
            if (state.curr_track != null) {
                state.curr_track.play();
                state.isPlaying = true;
            } else {
                alert('Please select a track first')
            }

        },
        pauseTrack(state) {
            // Pause the loaded track
            state.curr_track.pause();
            state.isPlaying = false;
        },
        setVolume(state, value) {
            // Set the volume
            state.curr_track.volume = value
        },

        /**
         * Play the next track: if the current track is the last track in the track list, then load the first track in the
         * track list. Otherwise, load the next track in the track list
         * @param state - the state object
         */
        playNext(state) {
            if (state.track_list == null) {
                alert('Please select a track first')
                return []
            }
            if (state.track_list[state.track_list.length - 1]['id'] == state.curr_track.id) {
                console.log('last track, go to first')
                this.commit('loadTrack', state.track_list[0])
            } else {
                console.log('go to next track')
                let curr_idx = state.track_list.findIndex(track => track.id == state.curr_track.id)
                this.commit('loadTrack', state.track_list[curr_idx + 1])
            }
        },

        /**
         * Play the previous track: if the current track is the first track in the track list, then load the last track in the
         * track list. Otherwise, load the previous track in the track list
         * @param state - the state object
         */
        playPrevious(state) {
            if (state.track_list[0]['id'] == state.curr_track.id) {
                console.log('first track, got to last one')
                this.commit('loadTrack', state.track_list[state.track_list.length - 1])
            } else {
                console.log('go to previous track')
                let curr_idx = state.track_list.findIndex(track => track.id == state.curr_track.id)
                this.commit('loadTrack', state.track_list[curr_idx - 1])
            }
        }
    },
    getters: {
        getIsPlaying(state) {
            return state.isPlaying
        },
        getCurrTrack(state) {
            return state.curr_track
        }

    },
    actions: {

    }
})

export default store


问:
Batch Split A3 pdfs (with two A4 pages side by side) into A4 pages and reorder them
Can anyone change any of the code on this page ....

https://stackoverflow.com/questions/13345593/split-each-pdf-page-in-two

to split a document of A3 pages into A4 pages so that they come out ordered. I need to do this to a whole folder of pdfs so ideally would like to be able to do it as a batch changing each filename from ABC.pdf to ABC A4.pdf Each A3 page is made of 2 A4 pages, with the following page numbers

A3 Page 1 is made of A4 page n : A4 page 1

A3 Page 2 is made of A4 page 2 : A4 page n-1

and so on.

Any help would be greatly appreciated - our photocopier will not scan a booklet to separate pages. Annoying!

I tried to use some of the code on Split each PDF page in two?

but it splits it in ways I don't want and I cannot work out the changes needed. I also need it to read all the pdfs from a folder and batch split them all.


问:
Dynamic Code Evaluation: Unsafe Deserialization for RedisTemplate
I get this error. Do you have any idea ? How can I solve this ?</p>
```<code>public RedisTemplate<String, Object> redisObjectTemplate(RedisConnectionFactory connectionFactory) {
</code>```

Body:
I get this error. Do you have any idea ? How can I solve this ?

public RedisTemplate<String, Object> redisObjectTemplate(RedisConnectionFactory connectionFactory) {


问:
Do not use a triple slash reference for
I'm trying to use a type declaration file. When using triple slash reference like so:

```<code>/// <reference path="../declarations.d.ts" />
</code>```

The app builds fine, but I get the above eslint error: "Do not use a triple slash reference for ../declarations.d.ts, use import style instead(https://typescript-eslint.io/rules/triple-slash-reference/)

If I do use an import:

```<code>import "../declarations.d.ts"
</code>```

The build fails and the declarations file is being ignored.

I also tried to use tsconfig.json to add the file, but that also failed (I'm using NX environment, probably there's some bug with NX)

So only the reference syntax is working, but then I get that es-lint error. Does anyone know how to fix this?

My custom declaration file:

```<code>import '@types/my-react-package';

declare module '@types/my-react-package' {
  export interface PackageProps {
    showPreview?: boolean;
  }
}
</code>```

Title: Do not use a triple slash reference for

Body:
I'm trying to use a type declaration file. When using triple slash reference like so:

/// <reference path="../declarations.d.ts" />

The app builds fine, but I get the above eslint error: "Do not use a triple slash reference for ../declarations.d.ts, use import style instead(https://typescript-eslint.io/rules/triple-slash-reference/)

If I do use an import:

import "../declarations.d.ts"

The build fails and the declarations file is being ignored.

I also tried to use tsconfig.json to add the file, but that also failed (I'm using NX environment, probably there's some bug with NX)

So only the reference syntax is working, but then I get that es-lint error. Does anyone know how to fix this?

My custom declaration file:

import '@types/my-react-package';

declare module '@types/my-react-package' {
  export interface PackageProps {
    showPreview?: boolean;
  }
}


问:
NodeJS redirect from handler
We need to direct from a Log Handler, this handler is being called from a route and I tried to use many ways, this is the latest that makes more sense but still it seems to not work. I would like no matter what, this direct always happens if it's called.

```<code>router.get('/AccessDenied', utils.CheckAuthenticated, function(req,res) {
    try {
      let ContentTitle = "Abcd1234"
    } catch (error) {
      CustomErrorLog(error, metadata)
    }
})
</code>```

The function CustomErrorLog is:

```<code>const logger = require("../services/logger")
const uuid = require("uuid");

module.exports = {
    CustomErrorLog: (error, metadata) => {
        return (req, res, next) => {
            let correlationId = uuid.v4()
            metadata["correlation_id"] = correlationId;
            logger.error(error, metadata);
            res.redirect('/error/' + errorId)
        }
    }
}
</code>```

I tried many different approaches and none seems to work. Any help is appreciated.

Title: NodeJS redirect from handler

Body:
We need to direct from a Log Handler, this handler is being called from a route and I tried to use many ways, this is the latest that makes more sense but still it seems to not work. I would like no matter what, this direct always happens if it's called.

router.get('/AccessDenied', utils.CheckAuthenticated, function(req,res) {
    try {
      let ContentTitle = "Abcd1234"
    } catch (error) {
      CustomErrorLog(error, metadata)
    }
})

The function CustomErrorLog is:

const logger = require("../services/logger")
const uuid = require("uuid");

module.exports = {
    CustomErrorLog: (error, metadata) => {
        return (req, res, next) => {
            let correlationId = uuid.v4()
            metadata["correlation_id"] = correlationId;
            logger.error(error, metadata);
            res.redirect('/error/' + errorId)
        }
    }
}

I tried many different approaches and none seems to work. Any help is appreciated.


问:
How to correctly send the CSRF token with Axios, React and Laravel 9. Request failed with status code 419
I'm using React, Inertia, Breeze and Laravel 9. When sending a request to the server with Axios, I get the following error: `{message: 'Request failed with status code 419', name: 'AxiosError', code: 'ERR_BAD_REQUEST'.

My code is the following (React):

```<code>const handleLogout = (e) => {
      e.preventDefault();
      const token = document.head.querySelector('meta[name="csrf-token"]').getAttribute('content');
      console.log(token);
      axios.post('logout', { name: 'John Doe' }, {
          headers: {
          'content-type': 'text/json',
          'X-CSRF-TOKEN': token
          }
      }
      );
    };
</code>```

and in my HTML I have:

```<code>            {{-- CSRF Token --}}
        <meta name="csrf-token" id="csrf-token" content="{{ csrf_token() }}">
</code>```

It correctly prints the token in console.log but throws me the error. Something when passing the token does not work for me.

Body:
I'm using React, Inertia, Breeze and Laravel 9. When sending a request to the server with Axios, I get the following error: `{message: 'Request failed with status code 419', name: 'AxiosError', code: 'ERR_BAD_REQUEST'.

My code is the following (React):

const handleLogout = (e) => {
      e.preventDefault();
      const token = document.head.querySelector('meta[name="csrf-token"]').getAttribute('content');
      console.log(token);
      axios.post('logout', { name: 'John Doe' }, {
          headers: {
          'content-type': 'text/json',
          'X-CSRF-TOKEN': token
          }
      }
      );
    };

and in my HTML I have:

            {{-- CSRF Token --}}
        <meta name="csrf-token" id="csrf-token" content="{{ csrf_token() }}">

It correctly prints the token in console.log but throws me the error. Something when passing the token does not work for me.


问:
Is there any way to restrict access to specific packages in modules in android while using java?
I have recently found out about an option in android studio to create modules. I have searched the internet for an option to restrict access to the module's classes from other modules, and found nothing. I saw that it is possible in kotlin using the "internal" keyword, but this keyword does not exist in java.
In the official Android Developers website, they talk about the benefits of modularity, about encapsulation, like modules somehow help in that. How can they help in that if the visibility modifiers stay the same?
From what I have seen, the modules in android studio just seperate the code into multiple folders, exactly like packages, but force you to import the module to the other module in order to use it.
Also, in the official website, they have best practices for using modules, and as a part of it they say that it is important to expose only the main parts of the module, and not the inner code that make it work.
If I can not control the exposure of my classes and packages, how can I do that?

I tried to search for module access modifiers to android studio in google, I tried to search for gradle options for restricting access, I tried to create a module myself and look for options during the creation process, I tried using kotlin's internal access modifier.

Nothing gave me answers. Nothing allowed me to restrict the access of parts of the module.

Thanks in advance!


问:
Uncaught ReferenceError for module, exports and require
I'm very new to Angular and node and I'm trying to build a simple Single Page Application using the latest version of angular cli.
I had to jump through a bunch of hoops to get it to even compile:

install angular-builders and browserified packages that are no longer polyfilled and add them to the extra-webpack.config.js

install node-loader so webpack can read :node scheme

add certain packages to "allowedCommonJsDependencies" in angular.json to get rid of warnings

Finally I can compile and serve my app to the browser and I'm greeted with the following errors in the console:

```<code>require chunk loading:34 Uncaught ReferenceError: module is not defined
    at require chunk loading:34:1
    at require chunk loading:39:1
    at require chunk loading:39:1
zone.js:2803 Uncaught ReferenceError: require is not defined
    at zone.js:2803:3
    at zone.js:2803:3
vendor.js:1 Uncaught ReferenceError: exports is not defined
    at vendor.js:1:1
external node-commonjs "worker_threads":1 Uncaught ReferenceError: require is not defined
    at external node-commonjs "worker_threads":1:1
    at external node-commonjs "worker_threads":1:1
</code>```

From what I can tell from researching this, is that some packages are using the CommonJS require() method to import stuff while the browser expects ES compliant import statements. But as far as I can tell I have no control over this.
I'm going to include some files that are possibly relevant:

angular.json

```<code>{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "oap-erp": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-builders/custom-webpack:browser",
          "options": {
            "customWebpackConfig": {
              "path": "./extra-webpack.config.js",
              "mergeRules": {
                "externals": "replace"
              }
            },
            "allowedCommonJsDependencies": [
              "jsonwebtoken",
              "node-domexception",
              "crypto",
              "http",
              "https",
              "fs",
              "rxjs"
            ],
            "outputPath": "dist/oap-erp",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": [
              "zone.js"
            ],
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "1mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-builders/custom-webpack:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "oap-erp:build:production"
            },
            "development": {
              "browserTarget": "oap-erp:build:development"
            }
          },
          "defaultConfiguration": "development",
          "options": {
            "sslKey": "../certs/localhost.key",
            "sslCert": "../certs/localhost.crt",
            "ssl": true
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "oap-erp:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "polyfills": [
              "zone.js",
              "zone.js/testing"
            ],
            "tsConfig": "tsconfig.spec.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          }
        }
      }
    }
  }
}

</code>```

package.json

```<code>{
  "name": "oap-erp",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular-builders/custom-webpack": "^15.0.0-beta.0",
    "@angular/animations": "^15.0.0",
    "@angular/common": "^15.0.0",
    "@angular/compiler": "^15.0.0",
    "@angular/core": "^15.0.0",
    "@angular/forms": "^15.0.0",
    "@angular/platform-browser": "^15.0.0",
    "@angular/platform-browser-dynamic": "^15.0.0",
    "@angular/router": "^15.0.0",
    "@pnp/nodejs": "^3.10.0",
    "@pnp/sp": "^3.10.0",
    "crypto-browserify": "^3.12.0",
    "fs-web": "^1.0.1",
    "https-browserify": "^1.0.0",
    "rxjs": "~7.5.0",
    "stream-browserify": "^3.0.0",
    "stream-http": "^3.2.0",
    "tslib": "^2.3.0",
    "url": "^0.11.0",
    "util": "^0.12.5",
    "xlsx": "^0.18.5",
    "zone.js": "~0.12.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^15.0.3",
    "@angular/cli": "~15.0.3",
    "@angular/compiler-cli": "^15.0.0",
    "@types/jasmine": "~4.3.0",
    "jasmine-core": "~4.5.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "node-loader": "^2.0.0",
    "typescript": "~4.8.2"
  }
}

</code>```

tsconfig.json

```<code>/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "ES2022",
    "module": "ES2022",
    "useDefineForClassFields": false,
    "lib": [
      "ES2022",
      "dom"
    ],
    "skipLibCheck": true
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  }
}

</code>```

extra-webpack.config.js

```<code>module.exports = {
    target: "node",
    node: {
        __dirname: false,
    },
    module: {
        rules: [
        {
            test: /\.node$/,
            loader: "node-loader",
        },
        ],
    },
    resolve: {
        fallback: {
            fs: require.resolve('fs-web'),
            http: require.resolve('stream-http'),
            https: require.resolve('https-browserify'),
            crypto: require.resolve('crypto-browserify'),
            url: require.resolve('url'),
            stream: require.resolve('stream-browserify'),
            util: require.resolve('util'),
        },
    },
    // externalsPresets: { node: true }
};
</code>```

ng version output

```<code>
Angular CLI: 15.0.3
Node: 18.12.1
Package Manager: npm 8.19.2
OS: win32 x64

Angular: 15.0.3
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1500.3
@angular-devkit/build-angular   15.0.3
@angular-devkit/core            15.0.3
@angular-devkit/schematics      15.0.3
@schematics/angular             15.0.3
rxjs                            7.5.7
typescript                      4.8.4

</code>```

Any help would be greatly appreciated. I knew the learning curve was going to be steep, but I'm kind of losing my mind over here =D.

I tried serving my app after a succesfull compile, but this resulted in js errors in console.

Edit: added output of ng version above.

Edit2: I tried using Babel in conjunction with webpack to transpile to es modules cf.: this article. But that didn't seem to change anything. I was under the impression that by implementing this any cjs modules would be translated by Babel to es modules but either I'm mistaken or I did it wrong, both very possible..

Body:
I'm very new to Angular and node and I'm trying to build a simple Single Page Application using the latest version of angular cli.
I had to jump through a bunch of hoops to get it to even compile:

install angular-builders and browserified packages that are no longer polyfilled and add them to the extra-webpack.config.js

install node-loader so webpack can read :node scheme

add certain packages to "allowedCommonJsDependencies" in angular.json to get rid of warnings

Finally I can compile and serve my app to the browser and I'm greeted with the following errors in the console:

require chunk loading:34 Uncaught ReferenceError: module is not defined
    at require chunk loading:34:1
    at require chunk loading:39:1
    at require chunk loading:39:1
zone.js:2803 Uncaught ReferenceError: require is not defined
    at zone.js:2803:3
    at zone.js:2803:3
vendor.js:1 Uncaught ReferenceError: exports is not defined
    at vendor.js:1:1
external node-commonjs "worker_threads":1 Uncaught ReferenceError: require is not defined
    at external node-commonjs "worker_threads":1:1
    at external node-commonjs "worker_threads":1:1

From what I can tell from researching this, is that some packages are using the CommonJS require() method to import stuff while the browser expects ES compliant import statements. But as far as I can tell I have no control over this.
I'm going to include some files that are possibly relevant:

angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "oap-erp": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-builders/custom-webpack:browser",
          "options": {
            "customWebpackConfig": {
              "path": "./extra-webpack.config.js",
              "mergeRules": {
                "externals": "replace"
              }
            },
            "allowedCommonJsDependencies": [
              "jsonwebtoken",
              "node-domexception",
              "crypto",
              "http",
              "https",
              "fs",
              "rxjs"
            ],
            "outputPath": "dist/oap-erp",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": [
              "zone.js"
            ],
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "1mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-builders/custom-webpack:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "oap-erp:build:production"
            },
            "development": {
              "browserTarget": "oap-erp:build:development"
            }
          },
          "defaultConfiguration": "development",
          "options": {
            "sslKey": "../certs/localhost.key",
            "sslCert": "../certs/localhost.crt",
            "ssl": true
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "oap-erp:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "polyfills": [
              "zone.js",
              "zone.js/testing"
            ],
            "tsConfig": "tsconfig.spec.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          }
        }
      }
    }
  }
}

package.json

{
  "name": "oap-erp",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular-builders/custom-webpack": "^15.0.0-beta.0",
    "@angular/animations": "^15.0.0",
    "@angular/common": "^15.0.0",
    "@angular/compiler": "^15.0.0",
    "@angular/core": "^15.0.0",
    "@angular/forms": "^15.0.0",
    "@angular/platform-browser": "^15.0.0",
    "@angular/platform-browser-dynamic": "^15.0.0",
    "@angular/router": "^15.0.0",
    "@pnp/nodejs": "^3.10.0",
    "@pnp/sp": "^3.10.0",
    "crypto-browserify": "^3.12.0",
    "fs-web": "^1.0.1",
    "https-browserify": "^1.0.0",
    "rxjs": "~7.5.0",
    "stream-browserify": "^3.0.0",
    "stream-http": "^3.2.0",
    "tslib": "^2.3.0",
    "url": "^0.11.0",
    "util": "^0.12.5",
    "xlsx": "^0.18.5",
    "zone.js": "~0.12.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^15.0.3",
    "@angular/cli": "~15.0.3",
    "@angular/compiler-cli": "^15.0.0",
    "@types/jasmine": "~4.3.0",
    "jasmine-core": "~4.5.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "node-loader": "^2.0.0",
    "typescript": "~4.8.2"
  }
}

tsconfig.json

/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "ES2022",
    "module": "ES2022",
    "useDefineForClassFields": false,
    "lib": [
      "ES2022",
      "dom"
    ],
    "skipLibCheck": true
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  }
}

extra-webpack.config.js

module.exports = {
    target: "node",
    node: {
        __dirname: false,
    },
    module: {
        rules: [
        {
            test: /\.node$/,
            loader: "node-loader",
        },
        ],
    },
    resolve: {
        fallback: {
            fs: require.resolve('fs-web'),
            http: require.resolve('stream-http'),
            https: require.resolve('https-browserify'),
            crypto: require.resolve('crypto-browserify'),
            url: require.resolve('url'),
            stream: require.resolve('stream-browserify'),
            util: require.resolve('util'),
        },
    },
    // externalsPresets: { node: true }
};

ng version output

Angular CLI: 15.0.3
Node: 18.12.1
Package Manager: npm 8.19.2
OS: win32 x64

Angular: 15.0.3
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1500.3
@angular-devkit/build-angular   15.0.3
@angular-devkit/core            15.0.3
@angular-devkit/schematics      15.0.3
@schematics/angular             15.0.3
rxjs                            7.5.7
typescript                      4.8.4

Any help would be greatly appreciated. I knew the learning curve was going to be steep, but I'm kind of losing my mind over here =D.

I tried serving my app after a succesfull compile, but this resulted in js errors in console.

Edit: added output of ng version above.

Edit2: I tried using Babel in conjunction with webpack to transpile to es modules cf.: this article. But that didn't seem to change anything. I was under the impression that by implementing this any cjs modules would be translated by Babel to es modules but either I'm mistaken or I did it wrong, both very possible..