-
-
Notifications
You must be signed in to change notification settings - Fork 660
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
Introduce ErrorContext for tracking errors across threads #83
Conversation
This is still a WIP. We now need to replace Some part of the new code here has introduced more race conditions causing tests to fail intermittently- they pass on increasing time b/w snapshots. |
Hey @kunalmohan - good start on this. I think, as you point out yourself and we start seeing in the implementation, that any solution forcing us to pass the error context very deep into the stack of functions in the thread itself would be very fragile and hard to maintain. This would mean that any developer who wants to add things would need to be aware of the inner workings of this error mechanism. And worst yet - remember to do things differently. :) This is of course true to being unable to use When I think about it, the only thing we really need in addition to the backtrace of the final thread is knowing which threads the error passed through and which instructions (be it |
Yep, basically logging the
I'm not sure if any of this matches to your idea of globally logging an |
To be honest, I'm more leaning toward option 1. I think most (all?) paths are rather unique and there will mostly be just one "open call" the user will have to choose from. I'd even say to just display the first one and assume there are no others. Or am I missing something and this doesn't make sense? (edit: ping @kunalmohan - forgot :) ) |
This makes sense. We don't have a large number of threads that the user needs to navigate through so it should not be very difficult. And I think you're correct about the paths being unique so I guess we should go ahead with this. Just to be very clear (before I start work on this), we'll only log the first open call, i.e. only the |
Hmm... maybe I didn't understand you correctly. I was thinking to log the previous calls in memory, and then dump them with the backtrace to screen somehow. |
So that in the end we'll have something like EDIT: forgot to add stdin thread :) |
Right, sorry, it slipped from my mind. I had just one concern with it. We'll use
Also, could you briefly explain what you meant by this? |
@kunalmohan - I think I might have been too general here in my thoughts and caused some confusion. Let's take a step back. If we:
Could we forgo having something global to the whole app shared with an |
I don't know if it will work, but maybe we can somehow use catch_unwind inside each thread to forward the |
@imsnif I guess I found a solution. We'll have a thread_local!(static OpenCalls: RefCell<ErrorContext> = RefCell::new(ErrorContext::new()); When a thread sends a message to another thread, we'll clone the current |
Interesting. I haven't used |
When accessing a Since we will be accessing the In short, you are correct :) |
@kunalmohan - sounds like a great solution. Looking forward to see the implementation :) |
An example of how the context is displayed-
|
@imsnif this is ready for the first round of review. All tests are passing on my local machine. I guess again some race conditions are causing failures in CI. |
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.
@kunalmohan - I think your solution with thread_local
and OPENCALLS
is very elegant. I could not have imagined anything simpler. Very cool :)
I left some comments about the implementation. We might have to do some back-and-forth about this, because this is a relatively big and very "deep" feature. I hope you can be a little patient with me. :)
Other than that, about displaying:
What do you think of adding some nice colors? Instead of
ErrorContext {
calls: [
"stdin_handler_thread(AcceptInput)",
"pty_thread(SpawnTerminalVertically)",
"stream_terminal_bytes(AsyncTask)",
"screen_thread(HandlePtyEvent)",
],
}
something like:
Originating thread(s):
1. stdin_handler_thread(purple): AcceptInput(green)
2. pty_thread(purple): SpawnTerminalVertically(green)
3. stream_terminal_bytes(purple): AsyncTask(green)
4. screen_thread(purple): HandlePtyEvent(green)
Error: <message>(red)
<stacktrace>(reset color)
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.
Looking good! Added some more comments
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.
Everything looks great. Thanks for being so patient (and quick!) with all my requests and suggestions. This is top notch work! I would be very happy to keep seeing you contributing and taking part in our project. :)
fix #61
Tracks and stores function names that send messages across threads. This information will then be passed to
PanicInfo
as payload for displaying at panic.