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/3178 crash on shutdown #3382

Conversation

LuxoftAKutsan
Copy link
Contributor

Fixes #3178

This PR is ready for review.

Risk

This PR makes no API changes.

Testing Plan

Script should be created.

Summary

We used aggregation in Thread class and we dont have contorol over
delegate life cycle, so logically need first to delete container and then delete delegate.
we are calling join() -> stop() Inside destuctor of Thread
we are using delegate_->exitThreadMain(); Inside the stop()

Shutdown () was removed because it is redundant. Destructor Thread will make this.


The core crash shows evidence that something around set_delegate is
crashing, on the other hand ~MessageLoopThread is deleting the thread
and not assigning the thread pointer to NULL which is necessary to avoid
undefined behavior

Tasks Remaining:

  • Create script for the issue
  • Internal Luxoft review
  • Check regression

CLA

ZhdanovP and others added 2 commits May 20, 2020 11:53
…thread

SDLCORE-534

We used aggregation in Thread class and we dont have contorol over
delegate life cycle, so logically need first to delete container and then delete delegate.
we are calling join() -> stop() Inside destuctor of Thread
we are using delegate_->exitThreadMain(); Inside the stop()

Shutdown () was removed because it is redundant. Destructor Thread will make this.
SDLCORE-679

The core crash shows evidence that something around set_delegate is
crashing, on the other hand ~MessageLoopThread is deleting the thread
and not assigning the thread pointer to NULL which is necessary to avoid
undefined behavior
@AByzhynar
Copy link
Contributor

@LuxoftAKutsan In the PR description you have stated the following:

Shutdown () was removed because it is redundant.

As I can see it was not removed. Remove it please or change PR description.

threads::DeleteThread(thread_);
thread_ = NULL;
Copy link
Contributor

@AByzhynar AByzhynar May 20, 2020

Choose a reason for hiding this comment

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

@LuxoftAKutsan Why did you set thread_ pointer to NULL after deletion but did not set thread_delegate_ to NULL after deletion? It is a pointer as well.

@Jack-Byrne
Copy link
Collaborator

Potential related fix #3388

@iCollin
Copy link
Collaborator

iCollin commented May 21, 2020

Thread delegates must be destroyed before threads.

Otherwise, when the delegate is destroyed it will attempt to write on the thread pointer that has been deleted.

ThreadDelegate::~ThreadDelegate() {
  if (thread_) {
    thread_->set_delegate(NULL);
  }
}

@@ -148,8 +148,9 @@ MessageLoopThread<Q>::MessageLoopThread(const std::string& name,
template <class Q>
MessageLoopThread<Q>::~MessageLoopThread() {
Shutdown();
delete thread_delegate_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thread delegate must be deleted before the thread itself. All threads in the project follow this pattern

@theresalech
Copy link
Contributor

@LuxoftAKutsan, can you please let us know when this is ready for re-review?

@theresalech theresalech added the Waiting for Feedback Maintainers are waiting for feedback from an author or contributor label Jul 1, 2020
@LuxoftAKutsan
Copy link
Contributor Author

@theresalech this work is planned. We will notify when fix with test scripts will be available.

@LuxoftAKutsan
Copy link
Contributor Author

Agree with PM comments.

Tested attached script on current develop looks like issued covered with #3388 fix.

@theresalech theresalech removed the Waiting for Feedback Maintainers are waiting for feedback from an author or contributor label Sep 2, 2020
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.

7 participants