Run testcontainer test OK in local environment but failed in jenkins - docker

Background
In my application, it needs to connect to zookeeper to get some useful information. So I start a zookeeper container in my integration test with port binding like -p 2859:2181.
zookeeper = new GenericContainer<>("zookeeper:3.6.1")
.withEnv("ZOOKEEPER_CLIENT_PORT", "2181")
.withExposedPorts(2181);
zookeeper.setPortBindings(Arrays.asList("2859:2181"));
zookeeper.start();
Then I use the following command to run the test. It goes smoothly connecting to localhost:2859 without any problems.
mvn -Dtest=xxxIntegrationTest.java test
Problem
However, when I use jenkins to run the same test with same command, it cannot connect to localhost:2859, complaining that
2020-10-28 12:16:04.282 INFO [main-SendThread(localhost:2859)] Opening socket connection to server localhost/127.0.0.1:2859. Will not attempt to authenticate using SASL (unknown error)
2020-10-28 12:16:04.283 WARN [main-SendThread(localhost:2859)] Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:350)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1068)
I don't know why it behaves differently in these two senarios. Could anyone give me some suggestions?

Related

Using DevTools features with Selenium Grid on Docker

I managed to work with DevTools features in Selenium 4 locally, but when I tried to use it on Selenium Grid, it didn't work.
In order to investigate it, I installed a local grid with one Chrome node using docker-compose and I got the same error:
OpenQA.Selenium.WebDriverException : Unexpected error creating WebSocket DevTools session.
----> System.Net.WebSockets.WebSocketException : Unable to connect to the remote server
----> System.Net.Http.HttpRequestException : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (172.18.0.3:4444)
----> System.Net.Sockets.SocketException : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Where 172.18.0.3 is the private IP of chrome-node container.
I guess that the main reason is that I don't have access to that IP from the host, and that's probably a docker configuration matter, on which I'm not an expert. But that wasn't the only problem.
Using the debugger, I was able to track that the driver tries to use this address due to the following capability that is returned from the driver after creation: "se:cdp": "ws://172.18.0.3:4444/session/2c519f679e1060cdc926ca74e63e222f/se/cdp". I then tweaked this value (in the debugger, before trying to create the connection to the DevTools protocol) to use localhost instead of the private IP, and then I got the following error: IOException: The response ended prematurely..
What do I need to do in order to use the DevTools features of Selenium through Selenium Grid (and docker)?
Adding - SE_NODE_GRID_URL=http://localhost:4444/ environment to the "chrome" container in the docker-compose yaml file solves the problem.
If you want to access the grid from outside of the host, instead of localhost write the IP or name of the machine.

Connection refused trying to get account info in Solana

solana account <address>
When I get account info, I have this error:
Error: RPC request error: cluster version query failed: error sending request for url (http://localhost:8899/): error trying to connect: tcp connect error: Connection refused (os error 111)
The error is indicating that the CLI RpcClient can not communicate with the Solana validator.
This is usually caused by not having solana-test-validator running in another terminal. Many make the mistake of thinking that the localhost is running the validator all the time... it's not.
In one terminal do: solana-test-validator which will startup up the local validator
Open a second terminal and do solana account - This will return account info for the default keypair
It's a network connection problem.
I use ubuntu 20.04, I was using windscribe VPN because my location and got the error, now I'm using psiphon VPN and it's working fine.

OWASP ZAP Docker Full Scan Fails with Proxy Error

I am attempting to perform a full scan against my application using the OWASP ZAP docker packaged scan, however the scans are failing to connect to the proxy with ProxyError, and the error seems to be inconsistent. Sometimes it will be NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f89c980ee80>: Failed to establish a new connection: [Errno 111] Connection refused'), other times it will be ConnectionResetError(104, 'Connection reset by peer').
The command I am using is basic one from the documentation:
docker run -t owasp/zap2docker-stable zap-full-scan.py -t https://my.webapp.com
Running the baseline-scan works without issue, and running the full-scan against other demo sites works fine too.
As suggested I have run curl against my application from inside the container and 200 is returned as expected, so I am unsure what needs to be configured to enable the connection.

Spring AMQP unable to connect back to RabbitMQ server after rabbitMQ server is restarted

Our application is able to connect to RabbitMQ server, messages get received in the message listeners, everything works fine. But when RabbitMQ is restarted then, we get below exception in the logs and messages are not received in the listeners. Once we restart our application container as well, then everything starts working. We cannot restart our application in Prodcution environment and we want the application to be able to recover connection to RabbitMQ once RabbitMQ server is up. Can someone please help.
2018-05-10 09:10:01,561[SimpleAsyncTaskExecutor-34]|DEBUG|org.springframework.beans.factory.support.DefaultListableBeanFactory|13-org.springframework.beans-3.1.4.RELEASE|Returning cached instance of singleton bean 'org.springframework.amqp.core.Queue#3'
2018-05-10 09:10:01,560[SimpleAsyncTaskExecutor-27]|DEBUG|org.springframework.amqp.rabbit.listener.BlockingQueueConsumer|435-wrap_file_._jetstream_thirdparty_spring-rabbit-1.3.6.RELEASE.jar-0.0.0|Closing Rabbit Channel: null
2018-05-10 09:10:01,563[SimpleAsyncTaskExecutor-34]|DEBUG|org.springframework.amqp.rabbit.listener.BlockingQueueConsumer|435-wrap_file_._jetstream_thirdparty_spring-rabbit-1.3.6.RELEASE.jar-0.0.0|Starting consumer Consumer: tags=[[]], channel=null, acknowledgeMode=MANUAL local queue size=0
2018-05-10 09:10:01,560[SimpleAsyncTaskExecutor-32]|DEBUG|org.springframework.beans.factory.support.DefaultListableBeanFactory|13-org.springframework.beans-3.1.4.RELEASE|Returning cached instance of singleton bean 'org.springframework.amqp.core.Queue#1'
2018-05-10 09:10:01,559[SimpleAsyncTaskExecutor-29]|WARN|org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer|435-wrap_file_._jetstream_thirdparty_spring-rabbit-1.3.6.RELEASE.jar-0.0.0|Consumer raised exception, processing can restart if the connection factory supports it
org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:54)[435:wrap_file_._jetstream_thirdparty_spring-rabbit-1.3.6.RELEASE.jar:0]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:195)[435:wrap_file_._jetstream_thirdparty_spring-rabbit-1.3.6.RELEASE.jar:0]
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:371)[435:wrap_file_._jetstream_thirdparty_spring-rabbit-1.3.6.RELEASE.jar:0]
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:80)[435:wrap_file_._jetstream_thirdparty_spring-rabbit-1.3.6.RELEASE.jar:0]
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:130)[435:wrap_file_._jetstream_thirdparty_spring-rabbit-1.3.6.RELEASE.jar:0]
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:67)[435:wrap_file_._jetstream_thirdparty_spring-rabbit-1.3.6.RELEASE.jar:0]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:365)[435:wrap_file_._jetstream_thirdparty_spring-rabbit-1.3.6.RELEASE.jar:0]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1009)[435:wrap_file_._jetstream_thirdparty_spring-rabbit-1.3.6.RELEASE.jar:0]
at java.lang.Thread.run(Thread.java:745)[:1.7.0_80]
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)[:1.7.0_80]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)[:1.7.0_80]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)[:1.7.0_80]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)[:1.7.0_80]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)[:1.7.0_80]
at java.net.Socket.connect(Socket.java:579)[:1.7.0_80]
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:625)[:1.7.0_80]
at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:50)[432:com.rabbitmq.client:4.3.0]
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:61)[432:com.rabbitmq.client:4.3.0]
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:99)[432:com.rabbitmq.client:4.3.0]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:925)[432:com.rabbitmq.client:4.3.0]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:884)[432:com.rabbitmq.client:4.3.0]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:842)[432:com.rabbitmq.client:4.3.0]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1026)[432:com.rabbitmq.client:4.3.0]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:191)[435:wrap_file_._jetstream_thirdparty_spring-rabbit-1.3.6.RELEASE.jar:0]
... 7 more
This exception seems wierd to me because, if RabbitMQ is refusing connections then, how is the connection established when we do an application restart.
This issue is giving me a very hard time.
The 1.3.6 is too old and out of support version. Would be great if you consider to upgrade to the latest one: https://projects.spring.io/spring-amqp/, at least 1.7.7 . Also read this: https://docs.spring.io/spring-amqp/docs/2.0.3.RELEASE/reference/html/_reference.html#auto-recovery.

Strange neo4j-shell issue connecting to Neo4j in a docker instance

I have a really strange problem connecting to a Neo4j instance running in a docker instance. But first things first, here is my set up:
Everything runs on a MacOS. I use boot2docker, so the actual Docker instances run in a VirtualBox. I am able to reproduce this issue with Neo4j 2.1.5 and with Neo4j 2.2.0-M04.
Additionally, I installed Neo4j locally via homebrew and it is version 2.1.7. It is installed to have a neo4j-shell available.
The docker instances are accessible from the outside via 192.168.59.104. The docker instance itself has a 172.17.0.x IP address.
The problem:
I try to connect with neo4j-shell like this: neo4j-shell -v -host 192.168.59.104 -port 1337 -name shell. After a couple of minutes, it fails with:
ERROR (-v for expanded information):
Connection refused
java.rmi.ConnectException: Connection refused to host: 172.17.0.2; nested exception is:
java.net.ConnectException: Operation timed out
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:130)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at com.sun.proxy.$Proxy1.welcome(Unknown Source)
at org.neo4j.shell.impl.AbstractClient.sayHi(AbstractClient.java:215)
at org.neo4j.shell.impl.RemoteClient.findRemoteServer(RemoteClient.java:63)
at org.neo4j.shell.impl.RemoteClient.<init>(RemoteClient.java:55)
at org.neo4j.shell.impl.RemoteClient.<init>(RemoteClient.java:43)
at org.neo4j.shell.ShellLobby.newClient(ShellLobby.java:165)
at org.neo4j.shell.StartClient.startRemote(StartClient.java:297)
at org.neo4j.shell.StartClient.start(StartClient.java:175)
at org.neo4j.shell.StartClient.main(StartClient.java:120)
Caused by: java.net.ConnectException: Operation timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 14 more
The interesting part is, that it fails by trying to connect 172.17.0.2 instead of the provided IP address.
What I did so far:
Double check neo4j.properties are correct
remote_shell_host=0.0.0.0 is set
remote_shell_port=1337 is set
check the ports are exposed properly with docker ps:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
099cfd1b8018 daneroo/neo4j:latest "/bin/bash -c /launc 3 minutes ago Up 3 minutes 0.0.0.0:1337->1337/tcp, 0.0.0.0:7474->7474/tcp neo4j
Some Google and SO searches, but without any success.
Different neo4j versions and docker images
Basic connection checks with telnet 192.168.59.104 1337. This is successful.
Catch up with Mark Needham at todays neo4j meetup
So, do I miss something? In theory this should happen every time you can access the Neo4j through another IP address than the Neo4j instance can see (e.g. if you run a Neo4j instance at home on a machine with the IP 192.168.x.y and you try to access it via your public IP you have at this time).
Where is the client, running outside the Neo4j environment, getting the internal IP address from? Is there a way to work around this issue?
I think it might be related to the RMI protocol that the shell uses to communicate with Neo4j.
Afaik RMI also uses some additional ports and it might redirect the initial request. there is a system property in Java that you might want to try to set in neo4j-wrapper.conf: -Djava.rmi.server.hostname=192.168.59.104
see:
http://courses.cs.washington.edu/courses/cse341/98au/java/jdk1.2beta4/docs/guide/rmi/rmiNetworkingFAQ.html
http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/javarmiproperties.html

Resources