Load Balance session information of above firewall connection.
As you can see from above screen dump sessions are still active in firewall and load balancer (36501 seconds) and do not see that user is really active on app as i have tested myself and do not get disconnected even i close the app.
I am running Couchbase CE 4.0 and sync gateway 1.2.0 and couchbase lite 1.3 on android device and 1.1 on iOS
By default Sync Gateway is going to send a heartbeat to maintain a continuous replication, which would explain why the load balancer idle settings aren’t terminating the request.
I don’t know the details about whether a client application would be expected to terminate an active continuous replication when the app is closed, or if the replication needs to be explicitly stopped. @jens, @hideki - can you shed any light on that?
In case application is forced to exit/close, the socket connection with the SG is disconnected. But I believe the SG or the proxy can not detect the disconnection immediately. I called it half-closed connection. I believe the SG can detect disconnection when SG sends heartbeat.
By “session” I think you mean “TCP connection”? These are probably the app connections to the “changes feed”, used for server push.
I am having a situation where my sessions are not closing even app force closed.
If an app process exits, any TCP sockets it was using are immediately closed by the kernel. The socket should immediately be closed on the server side too, as soon as it receives the close packet from the client. (That’s just basic TCP behavior, nothing specific to us.)
The replicator also closes the socket when the app tells it to stop.
Are you sure the app process has actually quit?
it seems like sync gateway is initiating a connection with client even client closed the app.
SG will never open a socket to the app. Maybe you mean that it’s trying to send data over one of these left-open sockets? If that happens, the server’s TCP stack will detect that it never got a response to its packet, and will close the socket.
This should only happen if connectivity between the device and server is lost (i.e. device moves out of WiFi/cell range, or interference causes all packets to be dropped), or if the device abruptly loses power. If the app process exits, the TCP implementation in the OS kernel will send a FIN packet to tell the other end that the connection is closed.
Most of the TCP sockets you’re seeing are HTTP connections opened by the OS’s HTTP library. Those are going to stay open a while in case the app sends more HTTP requests. The details of that are up to the HTTP implementation, which we don’t control.
(Actually, @hideki: on Android do we use an HTTP library built into CBL? In that case do we need to tell it to close sockets when the app is backgrounded?)
I have noticed even i restart Android device or shutdown and wait for a while does not close sessions. As restart give new public IP through 4G network and it creates sessions with new IP even though i do not open the application.
Only option to kill session through “force close” app option from Android Settings --> Application Manager and then select app and “Force Close”
I am planning on Keep alive settings and see how i go.
@Karunakar if you see sessions started after a reboot of the device, without opening the app, something must be starting up. The typical case would be a service started by a broadcast receiver listening for an on boot event.
What’s the structure of your app? Do you have any services, or just activities? Are you able to reproduce what you’re seeing with a simple test app?
Also, you can examine the network activity and processes directly on a device with adb. If you reboot, and start a shell on the device (“adb shell”) and run “ps”, do you see anything related to your app? Use netstat to look at network state.
Yes, it creates even i restart or power off the mobile device and power back again.
What’s the structure of your app?
Push and pull updated as the app gets updates from the server and changes made on app pushed back to server.
Do you have any services, or just activities?
It is based on activities and i may need to check with developer but what i understand from developer it is based on activity and only gets update if any change on server end and wise-versa otherwise it should chose sessions.
Are you able to reproduce what you’re seeing with a simple test app?
Yes i can reproduce this issue and can see sessions dies after N number of minutes (No idea about when sessions are closing as some closes with in 2 hours and some stays more than a day)
I will try tracing with adb and see any traffic related to app but in my testing i have noticed when i restart phone i get a new public IP and which is making two sessions on Firewall/load balancer/couchbase sync gateway as i could follow the traffic from external device public IP to load balancer and once it passed on to sync gateway i could not trace anymore as sync gateway does not have an option to record client IP.
I’d like to direct you back to looking at what processes are running after device boot. It simply makes no sense that your app would be trying to connect if it hasn’t been started in some way. Can you get a process listing after boot and after you see network traffic start?
Couchbase Lite is a library in your app, not a separate process. It’s not going to do anything on its own; for it to connect to the server, your app must have launched and started a Replication. Can’t you make your app log or hit a breakpoint or something when this happens, to diagnose it?