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

fix(compiler): Panic immediately when out of memory #1450

Merged
merged 1 commit into from
Oct 27, 2022
Merged

Conversation

ospencer
Copy link
Member

This is a bit of a fun bug I discovered while working on refactoring constructors. When an OutOfMemory is thrown, if any memory is allocated during the chain of exception printer calls, we wind up in an infinite loop: we're out of memory, so trying to allocate something to report that we're out of memory ends up entering the out of memory flow again.

This PR adds Exception.panic in the runtime to print a string and immediately hit unreachable, and changes the implementation of morecore to immediately panic when out of memory instead of following the normal exception handling logic which could potentially try to allocate memory.

This seemed like a reasonable approach to me, since (in the future) users shouldn't be allowed to catch an OutOfMemory error.

I didn't consider this a breaking change because the API changes are only in the runtime.

@ospencer ospencer requested a review from a team October 15, 2022 22:41
@ospencer ospencer self-assigned this Oct 15, 2022
Copy link
Member

@peblair peblair left a comment

Choose a reason for hiding this comment

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

Nice find. FWIW, there is precedent in other languages to support catching OutOfMemory, but I agree that it's not something we should leave in support for (and we can always add it back later).

@jozanza jozanza self-requested a review October 27, 2022 15:47
Copy link
Member

@marcusroberts marcusroberts left a comment

Choose a reason for hiding this comment

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

Good find!

@ospencer ospencer merged commit 943d47d into main Oct 27, 2022
@ospencer ospencer deleted the oscar/panic branch October 27, 2022 16:06
@github-actions github-actions bot mentioned this pull request Oct 27, 2022
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.

4 participants