-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Proposed fix for GC rooting + extensive notes on how/why are in TimerToken #2413
Changes from all commits
7be2f76
0d759fc
7569e53
881643f
d59cb29
3d3927f
6bbdd52
af15bbb
30c3b67
32807d4
42dbc1e
3fecc5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -561,10 +561,31 @@ internal static void IdentifyFailureType(Exception? exception, ref ConnectionFai | |
|
||
internal void EnqueueInsideWriteLock(Message next) | ||
{ | ||
var multiplexer = BridgeCouldBeNull?.Multiplexer; | ||
if (multiplexer is null) | ||
{ | ||
// multiplexer already collected? then we're almost certainly doomed; | ||
// we can still process it to avoid making things worse/more complex, | ||
// but: we can't reliably assume this works, so: shout now! | ||
next.Cancel(); | ||
next.Complete(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about that; another version had There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And to pre-empt the obvious "then why is this code here?": If I can't be absolutely sure we can't get into this scenario, I'd rather be paranoid; without the heartbeat, there are scenarios where messages might not be terminated. Emphasis: we should have a muxer: that's literally what the rest of the PR is meant to guarantee. Just if I'm wrong, I'd rather give people cancellation faults than give them nothing at all. |
||
} | ||
|
||
bool wasEmpty; | ||
lock (_writtenAwaitingResponse) | ||
{ | ||
wasEmpty = _writtenAwaitingResponse.Count == 0; | ||
_writtenAwaitingResponse.Enqueue(next); | ||
} | ||
if (wasEmpty) | ||
{ | ||
// it is important to do this *after* adding, so that we can't | ||
// get into a thread-race where the heartbeat checks too fast; | ||
// the fact that we're accessing Multiplexer down here means that | ||
// we're rooting it ourselves via the stack, so we don't need | ||
// to worry about it being collected until at least after this | ||
multiplexer?.Root(); | ||
} | ||
} | ||
|
||
internal void GetCounters(ConnectionCounters counters) | ||
|
@@ -1975,5 +1996,35 @@ private static RawResult ParseInlineProtocol(Arena<RawResult> arena, in RawResul | |
} | ||
return new RawResult(block, false); | ||
} | ||
|
||
internal bool HasPendingCallerFacingItems() | ||
{ | ||
bool lockTaken = false; | ||
try | ||
{ | ||
Monitor.TryEnter(_writtenAwaitingResponse, 0, ref lockTaken); | ||
if (lockTaken) | ||
{ | ||
if (_writtenAwaitingResponse.Count != 0) | ||
{ | ||
foreach (var item in _writtenAwaitingResponse) | ||
{ | ||
if (!item.IsInternalCall) return true; | ||
} | ||
} | ||
return false; | ||
} | ||
else | ||
{ | ||
// don't contend the lock; *presume* that something | ||
// qualifies; we can check again next heartbeat | ||
return true; | ||
} | ||
} | ||
finally | ||
{ | ||
if (lockTaken) Monitor.Exit(_writtenAwaitingResponse); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that #2392 is a different issue, the issue fixed by this PR was discovered by @NickCraver while working on PR #2408.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 - we'll refine release notes here, want to test with all combined manually