Create a listener connection supervisor so we can recover in case of database connection failure #74
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For more information on what this feature was designed to address check the issue #71
Goal
The user should be able to configure a supervisor thread for the listener connecion. When a listener connection is not detected by the supervisor it will open a new listener connection and reconnect the multiplexer.
Configuration
We can use a variable such as
PGWS_CHECK_LISTENER_INTERVAL
where the user can configure a number of milliseconds between checks, and keep the current system behaviour by setting it to0
. The default configuration would be0
so the feature is backwards compatible with the current behaviour.The time configured is roughly the maximum amount of time where messages could be lost due to the lack of listener.
Implementation details
We will have to ensure that the producer thread for the
Multiplexer
is dead to avoid leaving any dangling resource. It seems that the supervisor and the producer termination behaviour are orthogonal but to avoid additional complexity the new setting will bypass the existingshutdown the whole server
and just re-spawn the producer.In order to cancel the old thread we need to call the supervisor where the thread id of the open producer is available. Also, using the same
openProducer
function might simplify the code. One way to achieve both things is to keep both theopenProducer
function and the producerthreadId
in theMultiplexer
and have another function such assuperviseMultiplexer :: Multiplexer -> IO ()
which would take a multiplexer and launch the supervisor. We could also bake the supervisor inside eithernewHasqlBroadcasterForChannel
ornewMultiplexer
but those functions are complex enough as they are.TODO: