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

fix std::system_error when tcp interface loses connection #1682

Merged

Conversation

SylvainPastor
Copy link

When the tcp connection is lost (remote TCP server stopped), an End of file error is caught
by the io_thread in the do_recv() that calls the close() function.

In the close() function, we stop the io_service and wait the end of the io_thread which
causes an std::system_error exception (cause: Resource deadlock avoided).

  Error:   mavconn: tcp0: receive: End of file at line 250 in libmavconn/src/tcp.cpp
           terminate called after throwing an instance of 'std::system_error'
           what():  Resource deadlock avoided
           Aborted (core dumped)

fix:
- close() function: stop io_service if current thread id != io_thread id
- ~MAVConnTCPClient(): stop io_service and io_thread if thread is running

  When the tcp connection is lost (remote TCP server stopped), an 'End of file' error is caught
  by the io_thread in the do_recv() that calls the close() function.

  In the close() function, we stop the io_service and wait for the end of the io_thread which
  causes an std::system_error exception (cause: Resource deadlock avoided).

  Error:   mavconn: tcp0: receive: End of file at line 250 in libmavconn/src/tcp.cpp
           terminate called after throwing an instance of 'std::system_error'
           what():  Resource deadlock avoided
           Aborted (core dumped)

  fix:
    - close() function: stop io_service if current thread id != io_thread id
    - ~MAVConnTCPClient(): stop io_service and io_thread if thread is running
@SylvainPastor
Copy link
Author

Personally, in the close() function, I will not stop the io_service and io_thread.

Especially in the case where the connection is created by the MAVConnTCPServer (io_service used is the server service).

Copy link
Member

@vooon vooon left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!

@vooon vooon added this to the Version 2.1 milestone Dec 20, 2021
@vooon vooon added the fix label Dec 20, 2021
@SylvainPastor
Copy link
Author

I have 2 style errors, I will correct them

@vooon vooon merged commit 02af8ca into mavlink:ros2 Dec 20, 2021
SylvainPastor pushed a commit to SylvainPastor/mavros that referenced this pull request Mar 3, 2022
Same problems as for the TCP:
  - mavlink#1682: fix std::system_error when tcp interface loses connection
  - mavlink#1679: fix deadlock when call close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants