Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection: fix: reader go-routine is leaked on connection close #70

Merged
merged 1 commit into from
Apr 19, 2022

Commits on Apr 19, 2022

  1. connection: fix: reader go-routine is leaked on connection close

    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.
    fho authored and lukebakken committed Apr 19, 2022
    Configuration menu
    Copy the full SHA
    2dfde48 View commit details
    Browse the repository at this point in the history