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

Use IOApp#reportFailure instead of printStackTrace() for blocking EC #4044

Merged
merged 1 commit into from May 25, 2024

Conversation

fredfp
Copy link

@fredfp fredfp commented Mar 19, 2024

fixes #3993

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! We can probably target this at series/3.5.x so it can be released sooner than later :)

@fredfp
Copy link
Author

fredfp commented Mar 19, 2024

Thanks for the PR! We can probably target this at series/3.5.x so it can be released sooner than later :)

That would be great, is there anything I could/should do about it?

@armanbilge
Copy link
Member

Yes, you can rebase your branch and retarget the PR on GitHub.

@fredfp fredfp changed the base branch from series/3.x to series/3.5.x March 19, 2024 21:44
@fredfp
Copy link
Author

fredfp commented Mar 19, 2024

I'm not sure how to handle bincompat, I've pushed a 2nd commit with an attempt to address it.

threads,
threadPrefix,
blockerThreadPrefix,
reportFailure = t => self.compute.reportFailure(t))
Copy link
Member

Choose a reason for hiding this comment

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

Hang on, sorry. I'm just a little bit confused by this. Does this actually work?

Here's why I'm confused: this method is building the WorkStealingComputeThreadPool which will be installed as compute in self.compute. Thus we are implementing reportFailure of this ExecutionContext by delegating recursively to itself. Is that right or am I mixed up somehow?

Copy link
Author

Choose a reason for hiding this comment

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

You are absolutely right, thanks for spotting this. I went to check pre-3.4 source code and cats.effect.IOApp#reportFailure didn't exist at the time, so I reverted to the previous behaviour which is the best we can do.

@armanbilge armanbilge changed the title Use IOApp.reportFailure instead of printStackTrace() where possible Use IOApp#reportFailure instead of printStackTrace() where possible Mar 31, 2024
): (ExecutionContext, () => Unit) =
createDefaultBlockingExecutionContext(threadPrefix, _.printStackTrace())

private[effect] def createDefaultBlockingExecutionContext(
Copy link
Member

Choose a reason for hiding this comment

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

We should create a follow-up to make this public in 3.x.

Comment on lines 901 to 902
if (!NonFatal(t)) {
t.printStackTrace()
runtime.compute.reportFailure(t)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I'm look at this and suddenly I'm not so sure about this change. Here's the problem.

!NonFatal(t) "not non-fatal" i.e. it is a fatal error. When there is a fatal error (e.g. OutOfMemoryError) the JVM is in an inconsistent state and we cannot assume that it is safe to allocate.

The runtime.compute.reportFailure(t) may involve allocating an IO/Fiber and therefore is not safe to do in general.

Meanwhile t.printStackTrace() is know to be always safe.

@armanbilge armanbilge changed the title Use IOApp#reportFailure instead of printStackTrace() where possible Use IOApp#reportFailure instead of printStackTrace() for blocking EC Apr 23, 2024
@djspiewak djspiewak merged commit f18a00d into typelevel:series/3.5.x May 25, 2024
28 of 31 checks passed
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.

Allow overriding how fatal errors are printed
3 participants