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

mqtt_proxy: Execute retry_connect in main thread to prevent updating @_retrying race condition #22

Closed

Commits on Dec 9, 2020

  1. mqtt_proxy: Execute retry_connect in main thread

    timer_execute will execute registered method in main thread.
    Prevous implementation will causes unhandled retrying with the following error sequence:
    
    1. send_packet(MQTT::Packet::Subscribe) in mqtt_proxy.rb (running on `@connection_thread`)
    2. When https://github.com/njh/ruby-mqtt/blob/v0.5.0/lib/mqtt/client.rb#L554, and then keep_alive! method failed in client.rb (running on `@read_thread`)
    3. IOError occurred in https://github.com/njh/ruby-mqtt/blob/v0.5.0/lib/mqtt/client.rb#L556 in mqtt_proxy.rb (running on `@connection_thread`)
    4. Executed #retry_connect in mqtt_proxy.rb (running on `@connection_thread`)
    5. Before reached in https://github.com/toyokazu/fluent-plugin-mqtt-io/blob/master/lib/fluent/plugin/mqtt_proxy.rb#L93, `@retry_interval` second(s) passes in mqtt_proxy.rb (running on `@connection_thread`)
    6. During 5. execution, https://github.com/toyokazu/fluent-plugin-mqtt-io/blob/master/lib/fluent/plugin/mqtt_proxy.rb#L152 is executed in main thread
    7. Then, retry is disabled.
    
    In short, `@connection_thread` in mqtt_proxy.rb and main thread will
    causes updating `@_retrying` race condition.
    
    To prevent this race condition, we should use `timer_execute` for
    `#retry_connect` to execute retrying connection operation on main thread
    not executing it on `@connection_thread`.
    This race condition will not happen when every running retrying operation
    runs on main thread.
    
    Signed-off-by: Hiroshi Hatake <hatake@clear-code.com>
    cosmo0920 committed Dec 9, 2020
    Configuration menu
    Copy the full SHA
    3ecae4e View commit details
    Browse the repository at this point in the history