Skip to content

[C++] Thread deadlock in ObjectOutputStream #41862

Closed

Description

@icexelloss

Describe the bug, including details regarding any error messages, version, and platform.

I am seeing a deadlock when destructing an ObjectOutputStream. I have attached the stack trace.

I did some debugging and found that the issue seems to be that the mutex in question is already held by this thread (I checked the __owner field in the pthread_mutex_t which points to the hanging thread)

Unfortunately the stack trace doesn’t show exactly which mutex it is trying to lock. I wonder if someone more familiar with the IO code has some ideas what might be the issue and where to dig deeper?

arrow_object_output_stream_stacktrace.txt

Edit:
I am using Arrow 15.0.0

Component(s)

C++

Activity

  1. pitrou commented on May 29, 2024

    @pitrou
    Member

    Copying the temptative diagnosis I initially posted on the dev ML:

    It seems the problem lies here:

    state->pending_parts_completed.MarkFinished(state->status);

    The Future is marked finished with the ObjectOutputStream's mutex taken,
    and the Future's callback then triggers a chain of event which leads to
    calling the ObjectOutputStream destructor, which in turn tries to take
    the lock.

  2. pitrou commented on May 29, 2024

    @pitrou
    Member

    @icexelloss If I submit a PR trying to fix this, will it be possible for you to validate it with your use case?

  3. icexelloss commented on May 29, 2024

    @icexelloss
    ContributorAuthor

    Yep - I can cherry pick the patch internally and test.

  4. icexelloss commented on May 29, 2024

    @icexelloss
    ContributorAuthor

    @pitrou I am curious how did you find the HandleUploadOutcome method? I couldn't find it in the stacktrace.

  5. pitrou commented on May 29, 2024

    @pitrou
    Member

    It's frame 68 in the stacktrace :-)

  6. added a commit that references this issue on May 29, 2024
  7. pitrou commented on May 29, 2024

    @pitrou
    Member

    Ok, I have not one but two potential fixes, it would be nice if you could try each of them independently: #41875 , #41876

    Note that both seem desirable in any case.

  8. icexelloss commented on May 29, 2024

    @icexelloss
    ContributorAuthor

    Thanks @pitrou! I will test both out in the next couple of days!

  9. changed the title [-]Thread deadlock in ObjectOutputStream[/-] [+][C++] Thread deadlock in ObjectOutputStream[/+] on May 30, 2024
  10. icexelloss commented on May 30, 2024

    @icexelloss
    ContributorAuthor

    FYI I am testing #41875 Today, I will let it run through out the day because the it doesn't always happen quickly.

  11. icexelloss commented on May 31, 2024

    @icexelloss
    ContributorAuthor

    #41875 doesn't seem to work and with similar stacktrace :(

    I am rerunning it to double check

  12. 6 remaining items

  13. icexelloss commented on Jun 3, 2024

    @icexelloss
    ContributorAuthor

    Here is the stacktrace after I applied the #41875 patch

    Did you apply it to an old version of Arrow? I cannot find anything in recent versions that corresponds to this traceback line:

    #21 ~<lambda> (this=0x5b98d96d4578, __in_chrg=<optimized out>) at /tmp/build/ts/arrow/dataset/c/src/arrow/dataset/dataset_writer.cc:363
    

    It would be nice if you could test the PR itself.

    This is on Arrow 15. The line numbers are slightly off but this is the line that stack 21 is referring to:

    https://github.com/apache/arrow/blob/apache-arrow-15.0.0/cpp/src/arrow/dataset/dataset_writer.cc#L346

    (or on master)
    https://github.com/apache/arrow/blob/main/cpp/src/arrow/dataset/dataset_writer.cc#L346

  14. pitrou commented on Jun 3, 2024

    @pitrou
    Member

    Ok, thanks. That explains why the "fix" doesn't work then :-)

  15. icexelloss commented on Jun 3, 2024

    @icexelloss
    ContributorAuthor

    Ok, thanks. That explains why the "fix" doesn't work then :-)

    Sorry I am slightly confused. The "fix" doesn't work because I am using Arrow 15 and the fix only works on newer Arrow version?

  16. pitrou commented on Jun 3, 2024

    @pitrou
    Member

    No, I mean the traceback better explains why the fix doesn't work. It probably wouldn't work on latest Arrow either (though you can still try if that's easy for you).

  17. icexelloss commented on Jun 3, 2024

    @icexelloss
    ContributorAuthor

    I see. Trying #41876 then.

  18. icexelloss commented on Jun 6, 2024

    @icexelloss
    ContributorAuthor

    @pitrou I ran tests with #41876 for two days and didn't see a deadlock. So I think #41876 fixes the issue that I was seeing.

  19. pitrou commented on Jun 6, 2024

    @pitrou
    Member

    Cool, thanks!

  20. added this to the 17.0.0 milestone on Jun 10, 2024
  21. pitrou commented on Jun 10, 2024

    @pitrou
    Member

    Issue resolved by pull request 41876
    #41876

  22. icexelloss commented on Jun 10, 2024

    @icexelloss
    ContributorAuthor

    Thank you! @pitrou

  23. added
    Critical FixBugfixes for security vulnerabilities, crashes, or invalid data.
    on Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions