Skip to content

Fix race condition in event_subscriber.h - #11283

Merged
zcbenz merged 1 commit into
masterfrom
fix-event-subscriber-race
Dec 12, 2017
Merged

zcbenz merged 1 commit into
masterfrom
fix-event-subscriber-race

Conversation

@tarruda

@tarruda tarruda commented Nov 29, 2017

Copy link
Copy Markdown
Contributor

No description provided.

@tarruda
tarruda requested review from a team, deepak1556 and zcbenz November 29, 2017 11:35
@tarruda
tarruda force-pushed the fix-event-subscriber-race branch from 7d493a1 to 189fe43 Compare November 29, 2017 14:25
@tarruda
tarruda force-pushed the fix-event-subscriber-race branch from 189fe43 to 68bceb9 Compare November 29, 2017 15:58
@zcbenz zcbenz self-assigned this Dec 5, 2017
@zcbenz

zcbenz commented Dec 6, 2017

Copy link
Copy Markdown
Contributor

I think we don't need the handler_lock_ at all, both EventEmitted and destructor run in UI thread, so they can not have a race condition.

But there are crashes when emitting data while the URLJob is being destroyed, I'll try with a solution that fixes the root cause.

@tarruda

tarruda commented Dec 6, 2017 •

Copy link
Copy Markdown
Contributor Author

I think we don't need the handler_lock_ at all, both EventEmitted and destructor run in UI thread, so they can not have a race condition.

If I remember correctly, the SafePtr destructor always runs in the IO thread (since that's where URL jobs are destroyed), so it is possible that a "data" event is being emitted when URLJob is being destroyed (OnData handler cannot be executed).

But there are crashes when emitting data while the URLJob is being destroyed, I'll try with a solution that fixes the root cause.

Did you experience crashes with handler_lock_ + the new AutoLock added in this PR?

@zcbenz

zcbenz commented Dec 6, 2017

Copy link
Copy Markdown
Contributor

If I remember correctly, the SafePtr destructor always runs in the IO thread (since that's where URL jobs are destroyed), so it is possible that a "data" event is being emitted when URLJob is being destroyed (OnData handler cannot be executed).

The root cause is the code is trying to access URLJob while it is being destroyed, so it is a race condition when accessing URLJob and we should fix it on URLJob's side, instead of working around it on EventSubscriber's side.

I have created #11357 which uses weak pointer to avoid solving the race condition manually.

@zcbenz

zcbenz commented Dec 6, 2017

Copy link
Copy Markdown
Contributor

Closed in favor of #11357 .

@zcbenz zcbenz closed this Dec 6, 2017
@zcbenz
zcbenz deleted the fix-event-subscriber-race branch December 6, 2017 12:43
@zcbenz
zcbenz restored the fix-event-subscriber-race branch December 12, 2017 00:34
@zcbenz

zcbenz commented Dec 12, 2017

Copy link
Copy Markdown
Contributor

I'm reopening this since this PR does fix the crash while #11357 still have some problems.

@zcbenz zcbenz reopened this Dec 12, 2017
@tarruda

tarruda commented Dec 12, 2017

Copy link
Copy Markdown
Contributor Author

Thanks @zcbenz. Later I plan to add more tests that exercise URLRequestStreamJob better.

@zcbenz
zcbenz merged commit 19f1fef into master Dec 12, 2017
@zcbenz
zcbenz deleted the fix-event-subscriber-race branch December 12, 2017 01:49
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.

2 participants