Skip to content

Handle premature connection termination in connection tracking handler #1898

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

Merged
merged 1 commit into from
Feb 25, 2019

Conversation

gerhard
Copy link
Contributor

@gerhard gerhard commented Feb 25, 2019

Proposed Changes

If a connection disappears before the handler can get the relevant info from a connection_created event, the handler crashes.

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • Bug fix (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause an observable behavior change in existing systems)
  • Documentation improvements (corrections, new content, etc)
  • Cosmetic change (whitespace, formatting, etc)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask on the
mailing list. We're here to help! This is simply a reminder of what we are
going to look for before merging your code.

  • I have read the CONTRIBUTING.md document
  • I have signed the CA (see https://cla.pivotal.io/sign/rabbitmq)
  • All tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in related repositories

Further Comments

Not sure if this is a good idea, submitting it while in WIP to get some feedback. I'm looking at how to add a test for this - feels very complicated - is it worth it?

Discovered by @mkuratczyk

2019-02-21 16:47:03.086 [info] <0.1283.0> accepting AMQP connection <0.1283.0> (10.44.1.56:34784 -> 10.44.0.54:5672)
2019-02-21 16:47:03.239 [info] <0.1283.0> Connection <0.1283.0> (10.44.1.56:34784 -> 10.44.0.54:5672) has a client-provided name: perf-test-configuration
2019-02-21 16:47:03.254 [info] <0.1283.0> connection <0.1283.0> (10.44.1.56:34784 -> 10.44.0.54:5672 - perf-test-configuration): user 'test' authenticated and granted access to vhost '/'
2019-02-21 16:47:03.256 [error] <0.392.0> ** gen_event handler rabbit_connection_tracking_handler crashed.
** Was installed in rabbit_event
** Last event was: {event,connection_created,[{user_provided_name,<<"perf-test-configuration">>},{type,network},{pid,<0.1283.0>},{name,<<"10.44.1.56:34784 -> 10.44.0.54:5672">>},{port,5672},{peer_port,34784},{host,{0,0,0,0,0,65535,2604,54}},{peer_host,{0,0,0,0,0,65535,2604,312}},{ssl,false},{peer_cert_subject,''},{peer_cert_issuer,''},{peer_cert_validity,''},{auth_mechanism,<<"PLAIN">>},{ssl_protocol,''},{ssl_key_exchange,''},{ssl_cipher,''},{ssl_hash,''},{protocol,{0,9,1}},{user,<<"test">>},{vhost,<<"/">>},{timeout,60},{frame_max,131072},{channel_max,2047},{client_properties,[{<<"connection_name">>,longstr,<<"perf-test-configuration">>},{<<"product">>,longstr,<<"RabbitMQ">>},{<<"copyright">>,longstr,<<"Copyright (c) 2007-2019 Pivotal Software, Inc.">>},{<<"capabilities">>,table,[{<<"exchange_exchange_bindings">>,bool,true},{<<"connection.blocked">>,bool,true},{<<"authentication_failure_close">>,bool,true},{<<"basic.nack">>,bool,true},{<<"publisher_confirms">>,bool,true},{<<"consumer_cancel_notify">>,bool,true}]},{<<"information">>,longstr,<<"Licensed under the MPL. See http://www.rabbitmq.com/">>},{<<"version">>,longstr,<<"5.6.0">>},{<<"platform">>,longstr,<<"Java">>}]},{connected_at,1550767623053},{node,'[email protected]'},...],...}
** When handler state == []
** Reason == {error,{no_exists,['tracked_connection_on_node_rabbit@rabbitmq-2.rabbitmq-headless.rabbitmq.svc.cluster.local',{'[email protected]',<<"10.44.1.56:34784 -> 10.44.0.54:5672">>}]}}
2019-02-21 16:47:03.302 [info] <0.1292.0> accepting AMQP connection <0.1292.0> (10.44.1.56:34788 -> 10.44.0.54:5672)
2019-02-21 16:47:03.333 [info] <0.1292.0> Connection <0.1292.0> (10.44.1.56:34788 -> 10.44.0.54:5672) has a client-provided name: perf-test-consumer-0
2019-02-21 16:47:03.336 [info] <0.1292.0> connection <0.1292.0> (10.44.1.56:34788 -> 10.44.0.54:5672 - perf-test-consumer-0): user 'test' authenticated and granted access to vhost '/'
2019-02-21 16:47:03.942 [info] <0.1315.0> accepting AMQP connection <0.1315.0> (10.44.0.56:49878 -> 10.44.0.54:5672)
2019-02-21 16:47:03.963 [info] <0.1315.0> Connection <0.1315.0> (10.44.0.56:49878 -> 10.44.0.54:5672) has a client-provided name: perf-test-consumer-0
2019-02-21 16:47:03.972 [info] <0.1315.0> connection <0.1315.0> (10.44.0.56:49878 -> 10.44.0.54:5672 - perf-test-consumer-0): user 'test' authenticated and granted access to vhost '/'
2019-02-21 16:47:04.038 [info] <0.1337.0> accepting AMQP connection <0.1337.0> (10.44.0.56:49880 -> 10.44.0.54:5672)
2019-02-21 16:47:04.044 [info] <0.1337.0> Connection <0.1337.0> (10.44.0.56:49880 -> 10.44.0.54:5672) has a client-provided name: perf-test-producer-0
2019-02-21 16:47:04.048 [info] <0.1337.0> connection <0.1337.0> (10.44.0.56:49880 -> 10.44.0.54:5672 - perf-test-producer-0): user 'test' authenticated and granted access to vhost '/'

@gerhard gerhard changed the title Handle premature termination in conn tracking handler Handle premature connection termination in connection tracking handler Feb 25, 2019
@gerhard gerhard marked this pull request as ready for review February 25, 2019 16:13
Copy link
Collaborator

@lukebakken lukebakken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rabbit_connection_tracking:register_connection should be updated, instead, as there are other mnesia operations in that module that handle no_exists

@gerhard
Copy link
Contributor Author

gerhard commented Feb 25, 2019

Happy for @lukebakken to take this over 👍

);
ThisNode ->
try
rabbit_connection_tracking:register_connection(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelklishin if we're going to catch these errors, how about moving try ... catch into rabbit_connection_tracking:register_connection itself?

Copy link
Collaborator

@michaelklishin michaelklishin Feb 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's the handler's choice/responsibility to handle them. I don't know if we want to mask those errors for every caller and what the return value should be in that case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

If a connection disappears before the handler can get the relevant info
from a connection_created event, the handler crashes:

    2019-02-21 16:47:03.086 [info] <0.1283.0> accepting AMQP connection <0.1283.0> (10.44.1.56:34784 -> 10.44.0.54:5672)
    2019-02-21 16:47:03.239 [info] <0.1283.0> Connection <0.1283.0> (10.44.1.56:34784 -> 10.44.0.54:5672) has a client-provided name: perf-test-configuration
    2019-02-21 16:47:03.254 [info] <0.1283.0> connection <0.1283.0> (10.44.1.56:34784 -> 10.44.0.54:5672 - perf-test-configuration): user 'test' authenticated and granted access to vhost '/'
    2019-02-21 16:47:03.256 [error] <0.392.0> ** gen_event handler rabbit_connection_tracking_handler crashed.
    ** Was installed in rabbit_event
    ** Last event was: {event,connection_created,[{user_provided_name,<<"perf-test-configuration">>},{type,network},{pid,<0.1283.0>},{name,<<"10.44.1.56:34784 -> 10.44.0.54:5672">>},{port,5672},{peer_port,34784},{host,{0,0,0,0,0,65535,2604,54}},{peer_host,{0,0,0,0,0,65535,2604,312}},{ssl,false},{peer_cert_subject,''},{peer_cert_issuer,''},{peer_cert_validity,''},{auth_mechanism,<<"PLAIN">>},{ssl_protocol,''},{ssl_key_exchange,''},{ssl_cipher,''},{ssl_hash,''},{protocol,{0,9,1}},{user,<<"test">>},{vhost,<<"/">>},{timeout,60},{frame_max,131072},{channel_max,2047},{client_properties,[{<<"connection_name">>,longstr,<<"perf-test-configuration">>},{<<"product">>,longstr,<<"RabbitMQ">>},{<<"copyright">>,longstr,<<"Copyright (c) 2007-2019 Pivotal Software, Inc.">>},{<<"capabilities">>,table,[{<<"exchange_exchange_bindings">>,bool,true},{<<"connection.blocked">>,bool,true},{<<"authentication_failure_close">>,bool,true},{<<"basic.nack">>,bool,true},{<<"publisher_confirms">>,bool,true},{<<"consumer_cancel_notify">>,bool,true}]},{<<"information">>,longstr,<<"Licensed under the MPL. See http://www.rabbitmq.com/">>},{<<"version">>,longstr,<<"5.6.0">>},{<<"platform">>,longstr,<<"Java">>}]},{connected_at,1550767623053},{node,'[email protected]'},...],...}
    ** When handler state == []
    ** Reason == {error,{no_exists,['tracked_connection_on_node_rabbit@rabbitmq-2.rabbitmq-headless.rabbitmq.svc.cluster.local',{'[email protected]',<<"10.44.1.56:34784 -> 10.44.0.54:5672">>}]}}
    2019-02-21 16:47:03.302 [info] <0.1292.0> accepting AMQP connection <0.1292.0> (10.44.1.56:34788 -> 10.44.0.54:5672)
    2019-02-21 16:47:03.333 [info] <0.1292.0> Connection <0.1292.0> (10.44.1.56:34788 -> 10.44.0.54:5672) has a client-provided name: perf-test-consumer-0
    2019-02-21 16:47:03.336 [info] <0.1292.0> connection <0.1292.0> (10.44.1.56:34788 -> 10.44.0.54:5672 - perf-test-consumer-0): user 'test' authenticated and granted access to vhost '/'
    2019-02-21 16:47:03.942 [info] <0.1315.0> accepting AMQP connection <0.1315.0> (10.44.0.56:49878 -> 10.44.0.54:5672)
    2019-02-21 16:47:03.963 [info] <0.1315.0> Connection <0.1315.0> (10.44.0.56:49878 -> 10.44.0.54:5672) has a client-provided name: perf-test-consumer-0
    2019-02-21 16:47:03.972 [info] <0.1315.0> connection <0.1315.0> (10.44.0.56:49878 -> 10.44.0.54:5672 - perf-test-consumer-0): user 'test' authenticated and granted access to vhost '/'
    2019-02-21 16:47:04.038 [info] <0.1337.0> accepting AMQP connection <0.1337.0> (10.44.0.56:49880 -> 10.44.0.54:5672)
    2019-02-21 16:47:04.044 [info] <0.1337.0> Connection <0.1337.0> (10.44.0.56:49880 -> 10.44.0.54:5672) has a client-provided name: perf-test-producer-0
    2019-02-21 16:47:04.048 [info] <0.1337.0> connection <0.1337.0> (10.44.0.56:49880 -> 10.44.0.54:5672 - perf-test-producer-0): user 'test' authenticated and granted access to vhost '/'

cc @mkuratczyk

rabbit_connection_tracking_handler: handle more errors when registering a connection

Due to #1869, a connection can be accepted before connection tracking
tables were initialized/synced from a peer. The handler should log
a warning and not terminate, even if it would be restarted, to reduce
log noise and scare fewer operators for no real reason:
the condition is transient and should not normally last for more than
a few tenths of a second.

Use tracked connection ID in error message
@lukebakken lukebakken force-pushed the defend-conn-created-tracking branch from 663f213 to 0dccf40 Compare February 25, 2019 17:29
@lukebakken lukebakken merged commit 161c716 into master Feb 25, 2019
@lukebakken lukebakken deleted the defend-conn-created-tracking branch February 25, 2019 17:29
@lukebakken lukebakken added this to the 3.7.13 milestone Feb 25, 2019
lukebakken added a commit that referenced this pull request Feb 25, 2019
Handle premature connection termination in connection tracking handler

(cherry picked from commit 161c716)
@lukebakken
Copy link
Collaborator

Backported to v3.7.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants