-
Notifications
You must be signed in to change notification settings - Fork 521
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
ByteStack: detect overflow immediately #3949
base: series/3.5.x
Are you sure you want to change the base?
Conversation
btw, worth pointing out that currently on Scala.js, there are no otoh, I am concerned if this hurts performance to check for what is effectively a fatal error anyway. Suppose a fiber's stack overflows: is this a recoverable situation? On the JVM |
What I'm realizing is that actually we don't really care what What we do care about is if we can handle this gracefully in |
I'm not sure if we are able to treat this as an ordinary error that can be handled by users. Since error handling requires stack, which we have run out of ... However, we could self-cancel the fiber, since this creates an entirely new stack, and log the error via some side-channel. Edit: wait, what if we are in an uncancelable region? Hmm. cats-effect/core/shared/src/main/scala/cats/effect/IOFiber.scala Lines 1112 to 1119 in 0207637
|
You're right. As you say, we can't error, and can't cancel. (And obviously we can't go on.) So all this PR does is that we reliably throw the exception if this happens. But then that exception is unhandled, goes into I don't really know, what to do with this. It could be argued, that this is similar to a |
Actually, we can cancel. Sometimes. Not always. So I think that if our If we are not in a cancelable region ...
Then yes, I think we should raise a " |
Btw, this is predicated on the assumption that adding this check is not detectably detrimental to performance. 😅 |
Thinking about this more, I think I understand why it feels like "too much" (at least for me). Imagine if getting a fatal exception on the JVM shut down your entire machine. That would be too much 😁 In this context, we can imagine the For an However, when unsafe-running an Essentially we need a separate pathway for handling |
Yes, that's exactly it. But the more I think about this, the more I think that a hanging fiber might be the least bad thing. (Hanging fibers are obviously bad, but they're already permitted for resource safety reasons.) Shutting down just one IORuntime (as you say) might be also acceptable, although still feels a bit much. Regarding the performance concerns: it might be worth running some benchmarks with this branch. Whatever we do, it probably won't be any faster than this, as this uses a hotspot intrinsic. If it's already too slow, we probably have no chance of doing anything. |
Exactly. If it's already too slow, then our thoughtful discussion above is moot 😆 I was remembering this comment from
Well, not on Scala.js. JS performance seems sensitive to these kinds of checks, so sensitive that even Scala.js doesn't bother throwing IOOB exceptions for bad |
I think it's very likely that we're sensitive to these types of bounds checks. Regarding that ancient TODO btw, I did experiment with using I'll put this on my pile of "to benchmark" and see what shakes out. I agree with the way @armanbilge is describing it: we basically need our own version of an SOE to cover this scenario. It's unfathomably weird though, because we're talking about a situation where someone has recursed to staggering depth in a non tail-recursive way and hasn't popped back up. |
This is about #3907. The idea is to detect the overflow when it happens, and immediately throw. (Instead of writing a negative count into the
ByteStack
, and later get anArrayIndexOutOfBoundsException
.)