Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add timeout behaviors to the socket module
When a remote server becomes unavailable or non-responsive without properly terminating connections, any requests in-flight will wait indefinitely. A optional connection parameter `req_timeout` has been added. The default value is infinity, which preserves the existing behavior. If a non-infinite value is specified, it is used internally as a gen_server timeout value within epgsql_sock. If there are outstanding requests (determined by looking at the queue state) the timeout is applied. This also adds overall timeout to the initialization process. if the initialization messages - ending with ReadyForQuery - arrive at intervals greater than the timeout, the epgsql_sock will timeout. Notes: One request in queue can represent multiple pipelined requests to the PG server. In this case a single timeout is applied - and it gets restarted as the reply to each individual message sent is received. This is intentional, because any network activity from the postgres server indicates we have a valid connection to it. Limitations: This change only ensures support for the default `epgsql` interface. Additional behavior consideration is required to support the async interface. The timeout is not exact - intervening inbound messages (whether to perform new actions, or received from the PG server) will restart the timer. A further refinement will be to only reset the timeout when receiving messages from the server, and to reduce remaining time available if the message is received from another caller. That is not addressed in this changeset. Signed-off-by: Marc Paradise <marc@chef.io> Signed-off-by: Marc Paradise <marc.paradise@gmail.com>
- Loading branch information