Appium Error: Cannot find any free port in range 8200..8299 - testing

I'm running about 90 tests in Appium (Android emulator on iMac) and it was all fine until suddenly I started observing this error:
Starting logs capture with command: /Users/username/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 logcat -v threadtime
E selenium.common.exceptions.WebDriverException: Message: An unknown server-side
error occurred while processing the command. Original error: Cannot find any free port in range
8200..8299}. Please set the available port number by providing the systemPort capability or
double check the processes that are locking ports within this range and terminate these which
are not needed anymore
I did a few things to fix this problem but nothing worked:
1.
adb kill-server
adb reconnect
I did clean the emulator and restarted too.
Apart from this, I didn't find any port from 8200-8299 which is already being used in the system.
I did add systemPort capability as well but still I see the same error.
I have no idea how to fix this.
UPDATE:
Found some more logs and figured out that the port forwarding isn't being cleared by UIAutomator 2 (or adb) that's why I don't have issues with iOS but have issued in Android only. Here are the logs which is at the end of the appium server:
[debug] [35m[WD Proxy] [39m Proxying [DELETE /] to [DELETE http://127.0.0.1:8200/wd/hub/session/d1f94433-2c44-4dac-a836-461ab7f41130] with no body
[debug] [35m[UiAutomator2] [39m Deleting UiAutomator2 server session
[debug] [35m[WD Proxy] [39m Matched '/' to command name 'deleteSession'
[debug] [35m[WD Proxy] [39m Proxying [DELETE /] to [DELETE http://127.0.0.1:8201/wd/hub/session/37137b29-a9a6-4d83-b2d9-ce510f601a2d] with no body
[debug] [35m[UiAutomator2] [39m Deleting UiAutomator2 server session
where 127.0.0.1:8201 goes upto 127.0.0.1:8299 and deletes 100 active sessions which I don't expect.
Also, in netstat output I do see that TCP ports 127.0.0.1:8200 - 127.0.0.1:8299 (LISTEN) are open

Execute:
adb -s $UDID forward --remove-all
just before launching appium
and after to ensure that the ports used by the adb are free
see How do I stop an adb port forward?

Related

Ubuntu cloud images using qemu/kvm are not properly startin ssh service

Today, I have been experiencing a weird problem when starting a cloud-img based VM using qemu/kvm. Apparently SSH service is not starting properly in the guest, and I cannot access the VM. This is what I see in the logs:
See 'systemctl status ssh.service' for details.
[ OK ] Started Dispatcher daemon for systemd-networkd.
[ OK ] Stopped OpenBSD Secure Shell server.
Starting OpenBSD Secure Shell server...
[FAILED] Failed to start OpenBSD Secure Shell server.
See 'systemctl status ssh.service' for details.
[ OK ] Stopped OpenBSD Secure Shell server.
Starting OpenBSD Secure Shell server...
[FAILED] Failed to start OpenBSD Secure Shell server.
See 'systemctl status ssh.service' for details.
[ OK ] Started Snap Daemon.
Starting Wait until snapd is fully seeded...
[ OK ] Stopped OpenBSD Secure Shell server.
Starting OpenBSD Secure Shell server...
[FAILED] Failed to start OpenBSD Secure Shell server.
See 'systemctl status ssh.service' for details.
[ OK ] Stopped OpenBSD Secure Shell server.
Starting OpenBSD Secure Shell server...
[FAILED] Failed to start OpenBSD Secure Shell server.
See 'systemctl status ssh.service' for details.
[ OK ] Stopped OpenBSD Secure Shell server.
[FAILED] Failed to start OpenBSD Secure Shell server.
Also, if I try to log in using serial TTY, I am not able to log in using the credentials I have previously specified using cloud-localds.
It is something I have never experienced in years, but this came up today. I tried with different Ubuntu cloud images, different host machines... But nothing, the problem persists.
Does someone have any clue about what is going on and perhaps shed some light on it?
Thanks a lot

bind() failed: Cannot assign requested address (99) error while executing Selenium based automation test in server

I have code for web ui automation test created with Katalon, I have tried to run it locally and it worked well.
Then I push my code to server but when I run it from server, it failed. It failed to open the web/url that i want.
I generate the code to execute test from server but when I run that code this is happened :
bind failed
then it kept loading the browser until it timed out :
Can anyone suggest/comment or help with a solution for this?
This error message...
[SEVERE]: bind() failed: Cannot assign requested address (99)
...implies that the ChromeDriver was unable to bind the Browsing Context i.e. Chrome Browser session.
Initiating ChromeDriver with --verbose flag would have helped to debug the issue in a better way.
Solution
As per the documentation in [Errno 99] Cannot assign requested address when starting Dockerized web app the probhable cause and the solution would be to:
Close all processes that may be running on your port number. Assuming you are running on port 8000:
lsof -t -i tcp:8000 | xargs kill -9
You are probably using an app adress as localhost or 127.0.0.1 and you need to change it to 0.0.0.0
Another possible reason can be, google-chrome attempted to listen on IPv6 address, which was not enabled. You can either enable IPv6 support (which works only on Linux host) or ignore the error since ChromeDriver process will be listening on IPv4 after initial failed attempts.

Monit EXEC not working when monitored process dies

using Monit 5.15 on FreeBSD 10.2:
set daemon 5
set logfile syslog
set pidfile /var/run/monit.pid
set idfile /var/.monit.id
set statefile /var/.monit.state
set alert x#y.z
set mailserver localhost
set httpd port 2812 and
use address 192.168.40.72
allow 192.168.20.0/24
allow admin:monit
check process haproxy with pidfile /var/run/haproxy.pid
if failed host 192.168.40.72 port 9090 type tcp
then exec "/bin/sh -c '/bin/echo `/bin/date` >> /tmp/monit.test'"
When i run monit with -vI and i kill haproxy, i have the following output:
Adding net allow '192.168.20.0/24'
Adding credentials for user 'admin'
Runtime constants:
Control file = /usr/local/etc/monitrc
Log file = syslog
Pid file = /var/run/monit.pid
Id file = /var/.monit.id
State file = /var/.monit.state
Debug = True
Log = True
Use syslog = True
Is Daemon = True
Use process engine = True
Poll time = 5 seconds with start delay 0 seconds
Expect buffer = 256 bytes
Mail server(s) = localhost:25 with timeout 30 seconds
Mail from = (not defined)
Mail subject = (not defined)
Mail message = (not defined)
Start monit httpd = True
httpd bind address = 192.168.40.72
httpd portnumber = 2812
httpd ssl = Disabled
httpd signature = Enabled
httpd auth. style = Basic Authentication and Host/Net allow list
Alert mail to = root#localhost
Alert on = All events
The service list contains the following entries:
Process Name = haproxy
Pid file = /var/run/haproxy.pid
Monitoring mode = active
Existence = if does not exist then restart
Port = if failed [192.168.40.72]:9090 type TCP/IP protocol DEFAULT with timeout 5 seconds then exec '/bin/sh -c /bin/echo `/bin/date` >> /tmp/monit.test'
System Name = appsrv01
Monitoring mode = active
-------------------------------------------------------------------------------
pidfile '/var/run/monit.pid' does not exist
Starting Monit 5.15 daemon with http interface at [192.168.40.72]:2812
Starting Monit HTTP server at [192.168.40.72]:2812
Monit HTTP server started
'appsrv01' Monit 5.15 started
Sending Monit instance changed notification to root#localhost
'haproxy' process is running with pid 42999
'haproxy' zombie check succeeded
'haproxy' succeeded testing protocol [DEFAULT] at [192.168.40.72]:9090 [TCP/IP]
'haproxy' connection succeeded to [192.168.40.72]:9090 [TCP/IP]
'haproxy' process is running with pid 42999
'haproxy' zombie check succeeded
'haproxy' succeeded testing protocol [DEFAULT] at [192.168.40.72]:9090 [TCP/IP]
'haproxy' connection succeeded to [192.168.40.72]:9090 [TCP/IP]
'haproxy' process is running with pid 42999
'haproxy' zombie check succeeded
'haproxy' succeeded testing protocol [DEFAULT] at [192.168.40.72]:9090 [TCP/IP]
'haproxy' connection succeeded to [192.168.40.72]:9090 [TCP/IP]
'haproxy' process test failed [pid=42999] -- No such process
'haproxy' process is not running
Sending Does not exist notification to root#localhost
'haproxy' trying to restart
'haproxy' stop skipped -- method not defined
'haproxy' start method not defined
'haproxy' monitoring enabled
'haproxy' process test failed [pid=42999] -- No such process
'haproxy' process is not running
'haproxy' trying to restart
'haproxy' stop skipped -- method not defined
'haproxy' start method not defined
'haproxy' monitoring enabled
^CShutting down Monit HTTP server
Monit HTTP server stopped
Monit daemon with pid [48685] stopped
'appsrv01' Monit 5.15 stopped
Sending Monit instance changed notification to root#localhost
The EXEC Line never gets executed, i dont see any new lines in /tmp/monit.test
If i change the checked Port from 9090 to some invalid port, lets say 9190 and start monit (haproxy is running !), i see:
Starting Monit 5.15 daemon with http interface at [192.168.40.72]:2812
Starting Monit HTTP server at [192.168.40.72]:2812
Monit HTTP server started
'appsrv01' Monit 5.15 started
Sending Monit instance changed notification to root#localhost
'haproxy' process is running with pid 50703
'haproxy' zombie check succeeded
Socket test failed for [192.168.40.72]:9190 -- Connection refused
'haproxy' failed protocol test [DEFAULT] at [192.168.40.72]:9190 [TCP/IP] -- Connection refused
Sending Connection failed notification to root#localhost
'haproxy' exec: /bin/sh
'haproxy' process is running with pid 50703
'haproxy' zombie check succeeded
Socket test failed for [192.168.40.72]:9190 -- Connection refused
'haproxy' failed protocol test [DEFAULT] at [192.168.40.72]:9190 [TCP/IP] -- Connection refused
'haproxy' exec: /bin/sh
Why does the EXEC Line works here but not when i kill -9 haproxy ?
What i'm trying to do is get monit to run the exec in case of a haproxy failure. the exec line will then contain a command to switch the CARP IP to another host.
haproxy itself is monitored using zabbix, so the NOC can investigate the cause of the failure later.
When you kill -9 haproxy you're killing the daemon. So when monit performs this "check process" block, it's detecting that the process isn't there and restarting the process. It doesn't perform the check on that port because it sees the process isn't there.
It works when you give it an invalid port because the process is still alive. When it performs the port check it will fail that and run the script.
You should add an additional line to this check block that says
check process haproxy with pidfile /var/run/haproxy.pid
if failed host 192.168.40.72 port 9090 type tcp
then exec "/bin/sh -c '/bin/echo `/bin/date` >> /tmp/monit.test'"
if restarted then exec "/bin/sh -c '/bin/echo `/bin/date` >>/tmp/monit.test'"
This should run the shell commands on both a restart AND a failed host.

Remotely shut down RabbitMQ server

I have been trying to remotely kill a rabbitmq server but haven't been lucky so far. I can easily connect to it and publish and receive messages using the pika library.
Steps I have tried so far:
Used RabbitMQ's HTTP API to DELETE a connection
/api/connections/name
An individual connection. DELETEing it
willclose the connection. Optionally set the "X-Reason"
header when DELETEing to provide a reason.'
When I tried something like http://localhost:15672/api/connection/127.0.0.1:31332, I get an error:
{"error":"Object Not Found","reason":"\"Not Found\"\n"}
Used rabbitmqadmin locally
Tried to use rabbitmqctl to remotely shut down the rabbitmq server
rabbitmqctl
Here is how to do that using rabbitmqctl
set RABBITMQ_CTL_ERL_ARGS=-setcookie FWQUGISFBWECSKWFVFRP
rabbitmqctl.bat -n rabbit#gabriele-VirtualBox stop
Erlang
Here is one way to kill a remote node using Erlang:
erl -setcookie FXQUEISFFRECSKWCVB -sname thekiller#gabriele-VirtualBox
Eshell V6.4 (abort with ^G)
(thekiller#gabriele-VirtualBox)1> net_adm:ping('rabbit#gabriele-VirtualBox').
pong
(thekiller#gabriele-VirtualBox)2> rpc:call('rabbit#gabriele-VirtualBox', init, stop, []).
ok
(thekiller#gabriele-VirtualBox)3>
Start erl console using your .erlang.cookie and with -sname
with same rabbitmq domain (in my case gabriele-VirtualBox).
Test if you reach the node using ping
call rpc:call('rabbit#gabriele-VirtualBox', init, stop, []).
Done, you killed the remote node.
After a bit of troubleshooting all over again, I was able to use the HTTP API to kill active connections. The trick was that the whole connection name was to be url encoded.
In my case the connection name was:
127.0.0.1:31332 -> 127.0.0.1:15672
So when I tried the following I got an error:
http://localhost:15672/api/connection/127.0.0.1:31332 ==> object not found error
It worked only after I URL encoded the connection name and sending a CURL DELETE like this:
http://localhost:15672/api/connection/127.0.0.1%3A31332%20-%3E%20127.0.0.1%3A15672

SSL handshake with ActiveMQ server gives NullPointerException when connecting via SilverTunnel netlib

Summary
Connecting to ActiveMQ via TCP works fine with or without netlib.
Connecting via SSL works fine without netlib but fails with netlib.
Note: I'm using apache-activemq-5.6.0 and silvertunnel.org_netlib-0.14-beta.
This problem occurs whether using netlib's tcpipNetLayer or torNetLayer. However, only the tcpipNetLayer case is considered here to keep things simple.
BTW, SSL + netlib worked fine with the HornetQ messaging server (which implements SSL authentication differently) but HornetQ had problems that led me to try using ActiveMQ.
For convenience I have created a simple test case with a consumer and two different producers.
producer connects without netlib - works fine.
producer-tcpip connects with neltib using the tcpipNetLayer - the following errors occur:
With SSL debugging turned on for ActiveMQ the producer-tcpip program outputs to the console the following error message and then hangs:
ActiveMQ Transport: ssl://null:0, handling exception: java.lang.NullPointerException
This is midway through an SSL handshake because the producer-tcpip program generates the log4j message:
DEBUG org.apache.activemq.transport.failover.FailoverTransport - Attempting 0th connect to: ssl://localhost:61616
DEBUG org.apache.activemq.transport.WireFormatNegotiator - Sending: WireFormatInfo { version=9, properties={MaxFrameSize=104857600, CacheSize=1024, CacheEnabled=true, SizePrefixDisabled=false, MaxInactivityDurationInitalDelay=10000, TcpNoDelayEnabled=true, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]}
Then when the producer-tcpip program is killed (e.g. with a ctrl+C) then the activemq.log reports that:
WARN | Transport Connection to: tcp://127.0.0.1:49463 failed: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake | org.apache.activemq.broker.TransportConnection.Transport | ActiveMQ Transport: ssl:///127.0.0.1:49463
ERROR | Could not accept connection from tcp://127.0.0.1:49463: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake | org.apache.activemq.broker.TransportConnector | ActiveMQ Task-3
I have no idea what could be causing this or how it can be resolved. Can anyone help?
Steps to reproduce the problem (takes under 15 minutes):
download the test case
wget http://anandavala.info/miscl/testing-AMQ-Netlib-SSL.zip
unzip testing-AMQ-Netlib-SSL.zip
rm testing-AMQ-Netlib-SSL.zip
cd testing-AMQ-Netlib-SSL
Download latest ActiveMQ into the testing directory
wget https://www.apache.org/dist/activemq/apache-activemq/5.6.0/apache-activemq-5.6.0-bin.tar.gz
tar -xzf apache-activemq-5.6.0-bin.tar.gz
rm apache-activemq-5.6.0-bin.tar.gz
Edit conf/activemq.xml to accept ssl
gedit apache-activemq-5.6.0/conf/activemq.xml
replace the transportConnectors entry with the following lines (to enable SSL)
<transportConnectors>
<transportConnector name="ssl" uri="ssl://0.0.0.0:61616?needClientAuth=true"/>
</transportConnectors>
<sslContext>
<sslContext
keyStore="broker.ks" keyStorePassword="password"
trustStore="client.ks" trustStorePassword="password"/>
</sslContext>
start server
cd apache-activemq-5.6.0
bin/activemq start
view logging output
tail -f data/activemq.log
open another console then cd into the testing-AMQ-Netlib-SSL directory
Download latest SilverTunnel netlib into the testing directory
wget http://sourceforge.net/projects/silvertunnel/files/silvertunnel_Netlib/silvertunnel.org_netlib-0.14-beta.zip
unzip silvertunnel.org_netlib-0.14-beta.zip
rm silvertunnel.org_netlib-0.14-beta.zip
compile the source code into three runnable jar files in separate directories
ant
run the consumer
cd consumer
./consumer
open another console then cd into the testing-AMQ-Netlib-SSL/producer directory
run the producer
./producer
let it run for a bit to satisfy yourself that it works then kill the producer by hitting ctrl+C
run the producer-tcpip
cd ../producer-tcpip
./producer-tcpip
let it run for a bit to satisfy yourself that it has stalled at a NullPointerException then kill the producer-tcpip by hitting ctrl+C
notice the debug message in producer-tcpip's output
tail -f logs/output.log
also notice the error message that appears at the bottom of activemq.log (see the tail output from the first console window) or type at the current prompt
tail -f ../apache-activemq-5.6.0/data/activemq.log
Thanks for your help!