When a message was sent and it's response was received while the
connection was closed or an error happened, the reader go-routine could
get stuck and be leaked.
The reader go routine tries to send a received message to the unbuffered
c.rpc channel via the dispatch0() and dispatchN() methods.
The call() method reads from the rpc channel.
If an error happened while the dispatch method sends a message to the
rpc channel, the call() method could terminate because it read an error
from c.errors or because c.errors was closed.
To prevent the scenario:
- the reader go-routine now closes c.rpc when it terminates,
- The call() method, reads from c.rpc until a message was received or it
is closed. When c.rpc is closed, it reads an error from c.errors or
wait until c.errors is closed.
When it reads an error, it returns it. If it is closed it returns
ErrClosed.
This ensures that the messages is read from c.rpc before call() returns.
It also ensures that when a message was received that it is processed.
Previously it could happen that the message was silently ignored because
c.errors returned an error or was closed.
tests: add testcase to ensure reader routine terminates
Add a testcase for the bug that the reader go-routine tries to send a
message to the buffered rpc channel but call() terminated because it
read an error from the errors chan or the errors chan was closed.
It cause that reader routine gets stuck forever and does not terminate
when the connection is closed.
More information: rabbitmq#69.
This testcase does not reproduce the issue reliably, but it is triggered
in ~80% of executions.
Bump GH actions versions
add missing go.sum file
tests/TestRequiredServerLocale: close connection on testcase termination
The TestRequiredServerLocale testcase was not closing the connection
that it opened.
This caused the goleak detector in the
TestReaderGoRoutineTerminatesWhenMsgIsProcessedDuringClose testcase to
complain about a leaked heartbeat go-routine.
tests: remove duplicate goleak invocation
goleak is now called in TestMain().
The invocation in the
TestReaderGoRoutineTerminatesWhenMsgIsProcessedDuringClose testcase can
be removed.
tests/ExampleConnection_reconnect: close connection on termination
ExampleConnection_reconnect was not closing the opened connection on
termination. This caused the goleak checker to complain about a leaked
heartbeat go routine.
Close the connection.