PostgreSQL Connection to the server has been lost - postgresql

I installed postgreSQL server on a raspberry pi 4 with raspbian buster. When I try to connect from local network i have no problems about idle time. When i try to connect from my static public ip I can send command but if I didn't send anything for more than 3 minutes, it appears this message "Connection to the server has been lost".
I tried to install ufw and disable it, I used DMZ, I tried to change keepalive_idle, but i have always the same problem. Please help me.
sometimes the error is
"ERROR: SSL SYSCALL error: Operation timed out"
(Note: always if I am connected from public IP)

If you don't have the same issue from within your local network I assume the connection is being terminated by a network device sitting between the client and the server (a router most likely).
There are routers with small TCP timeout settings (such as 300 seconds) which is close to what you're experiencing.
Try to check (and increase if needed) the TCP timeout settings on your router (and any other devices you might have in between).
Edit:
I tried to find some info on that device (seems to be Sercomm VD625) and it does not seem you can easily change TCP timeout settings (maybe via telnet/ssh if it supports it).
However, a simpler solution might be to avoid keeping an open connection to PostgreSQL if you will have large idle intervals; just connect when you need to and close the connection afterwards.

Related

modbus(watlow F4T) allow to be connected, but does not allow to be read

the mobus (watlow F4T) allows for connection, my pc use a static IP and watlow F4T is also using a static IP(192.168.0.222), it works well on another laptop or pc, but it could not work on one windows 7 laptop.
The modbus use a 502 port and I checked firewall, and using telnet 192.168.0.222 502 there is no error message, if I use a different port the telnet returns a connection failure, so I assume port 502 is open.
I use ModbusTcpTest130 to test, same setting, when I try to read something from watlow F4T, it always mentions "unable to do modbus read, please check the port setting", as different laptop would work, so I assume there is something special on this laptop, anybody has clue?
update: I tried another pc, it works when I only use modbusTCP130, however, when I tried modbus poll (I forgot to close modbusTCP130 connection), it fails, then after close both modbus poll and modbustcp130, whatever I use modbusTCP130 or modbuspoll, both fail, so looks port not released?
How you are closing the port?. Just closing down the terminal?
When you are not sure that your port is closed, I would suggest rebout devices on both ends. Also make sure there are only one instance of terminal is running.
It wort to try change communication port on device to different one, to make sure that, on PC that port is not being use with diff applications.

tcp connection issue for unreachable server after connection

I am facing an issue with tcp connection..
I have a number of clients connected to the a remote server over tcp .
Now,If due to any issue i am not able to reach my server , after the successful establishment of the tcp connection , i do not receive any error on the client side .
On client end if i do netstat , it shows me that clients are connected the remote server , even though i am not able to ping the server.
So,now i am in the case where the server shows it is not connected to any client and on another end the client shows it is connected the server.
I have tested this for websocket also with node.js , but the same behavior persists over there also .
I have tried to google it around , but no luck .
Is there any standard solution for that ?
This is by design.
If two endpoints have a successful socket (TCP) connection between each other, but aren't sending any data, then the TCP state machines on both endpoints remains in the CONNECTED state.
Imagine if you had a shell connection open in a terminal window on your PC at work to a remote Unix machine across the Internet. You leave work that evening with the terminal window still logged in and at the shell prompt on the remote server.
Overnight, some router in between your PC and the remote computer goes out. Hours later, the router is fixed. You come into work the next day and start typing at the shell prompt. It's like the loss of connectivity never happened. How is this possible? Because neither socket on either endpoint had anything to send during the outage. Given that, there was no way that the TCP state machine was going to detect a connectivity failure - because no traffic was actually occurring. Now if you had tried to type something at the prompt during the outage, then the socket connection would eventually time out within a minute or two, and the terminal session would end.
One workaround is to to enable the SO_KEEPALIVE option on your socket. YMMV with this socket option - as this mode of TCP does not always send keep-alive messages at a rate in which you control.
A more common approach is to just have your socket send data periodically. Some protocols on top of TCP that I've worked with have their own notion of a "ping" message for this very purpose. That is, the client sends a "ping" message over the TCP socket every minute and the server responds back with "pong" or some equivalent. If neither side gets the expected ping/pong message within N minutes, then the connection, regardless of socket error state, is assumed to be dead. This approach of sending periodic messages also helps with NATs that tend to drop TCP connections for very quiet protocols when it doesn't observe traffic over a period of time.

TCP connection between client and server gone wrong

I establish a TCP connection between my server and client which runs on the same host. We gather and read from the server or say source in our case continuously.
We read data on say 3 different ports.
Once the source stops publishing data or gets restarted , the server/source is not able to publish data again on the same port saying port is already bind. The reason given is that client still has established connection on those ports.
I wanted to know what could be the probable reasons of this ? Can there be issue since client is already listening on these ports and trying to reconnect again and again because we try this reconnection mechanism. I am more looking for reason on source side as the same code in client sides when source and client are on different host and not the same host works perfectly fine for us.
Edit:-
I found this while going through various article .
On the question of using SO_LINGER to send a RST on close to avoid the TIME_WAIT state: I've been having some problems with router access servers (names withheld to protect the guilty) that have problems dealing with back-to-back connections on a modem dedicated to a specific channel. What they do is let go of the connection, accept another call, attempt to connect to a well-known socket on a host, and the host refuses the connection because there is a connection in TIME_WAIT state involving the well-known socket. (Stevens' book TCP Illustrated, Vol 1 discusses this problem in more detail.) In order to avoid the connection-refused problem, I've had to install an option to do reset-on-close in the server when the server initiates the disconnection.
Link to source:- http://developerweb.net/viewtopic.php?id=2941
I guess i am facing the same problem: 'attempt to connect to a well-known socket on a host, and the host refuses the connection'. Probable fix mention is 'option to do reset-on-close in the server when the server initiates the disconnection'. Now how do I do that ?
Set the SO_REUSEADDR option on the server socket before you bind it and call listen().
EDIT The suggestion to fiddle around with SO_LINGER option is worthless and dangerous to your data in flight. Just use SO_RESUSEADDR.
You need to close the socket bound to that port before you restart/shutdown the server!
http://www.gnu.org/software/libc/manual/html_node/Closing-a-Socket.html
Also, there's a timeout time, which I think is 4 minutes, so if you created a TCP socket and close it, you may still have to wait 4 minutes until it closes.
You can use netstat to see all the bound ports on your system. If you shut down your server, or close your server after forking on connect, you may have zombie processes which are bound to certain ports that do not close and remain active, and thus, you can't rebind to the same port. Show some code.

Socket -> Connection refused issue

I'm having an issue with Sockets and i can't resolve the problem.
I have 2 distincts machines on the same network. I try to send an object from the first machine to the second.
The second machine is the server, a thread that open a ServerSocket on the port 1456 is running on it. I call the accept() method and it seems to work fine.
When I try to connect to the server from the first machine I receive a ConnectException, Connection refused.
I did a lot of research and found that the port i'm trying to connect to is probably close (firewall issue). I found that the antivirus "avast" blocks the port, so I disable the antivirus and it worked fine ! For 5min...
I uninstalled the antivirus and then it became impossible again to connect to the server. I disabled the windows firewall on both machines. I restarted the machines after each actions.
Does someone have an idea about that?
thanks.

Session getting disconnected in the middle of working

Sessions are getting disconnected automatically (in the middle of working).
Disconnection happens for the users when they working by using telnet connection to Linux server via putty telnet application.
During the disconnection, the Network b/w utilization is high and no limitation for total number of users in a network.
Error "Hangup signal received (562)"
Any idea about this ??
The network connection was interrupted or a hangup signal was sent via "kill".
You mention network utilization being "high" when disconnects happen. How do you know that? What measurement are you looking at that tells you it is "high"? That might be a symptom of a networking issue that is at the root of the problem.
There are few directions:
OpenEdge has published this article with links to implementing keep-alive packets:
https://knowledgebase.progress.com/articles/Article/Telnet-connection-times-out-after-15-minutes
Increase the number of "instances" in xinetd.conf, and then restart the service.
Make sure that the database watchdog is up and running: https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dmadm/prowdog-command.html
Check the database log file, to find out what happened just before the hangup (https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/gsins/openedge-database-log-file.html)