Skip to content

Conversation

@ruslandoga
Copy link
Contributor

@ruslandoga ruslandoga commented Oct 10, 2024

Continues #299

if (!columns) {
return make_error_tuple(env, "out_of_memory");
// TODO: should be exception, otherwise it's practically invisible
return make_error_tuple(env, am_out_of_memory);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

make_row and maybe other functions might need to be reworked to return this as an error tuple and not an element of a list of rows.

Copy link
Member

@warmwaffles warmwaffles Oct 10, 2024

Choose a reason for hiding this comment

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

I agree with this TODO, it probably should raise. Although what will most likely happen is that it won't be able to raise because the VM cannot allocate enough memory for the exception struct and message regardless. The programmer is going to be in for a world of pain.

But hopefully on the flip side, is that if the VM is able to free some memory, this call unblocks and completes the raise.

Copy link
Contributor Author

@ruslandoga ruslandoga Oct 10, 2024

Choose a reason for hiding this comment

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

Yeah, that's also something I've been thinking about: would any of the current out_of_memory errors ever surface or would the app just be OOM-killed. I have seen these errors in all of SQLite Erlang/Elixir bindings I could find and in https://github.com/jlouis/enacl as well, but I wonder if those code paths were ever actually executed ...

I think trying to raise is still a good strategy though.


UPDATE: Went to see how enacl is doing it now, and it seems like they have removed alloc_failed atoms in favor of "internal_error": jlouis/enacl@59b9443#diff-43b9ee1b39907dcfc3d096225f5550664a88e3c8a100392e77a0dfb25082a634L171. And also removed many of error tuples in favor of raising exceptions as well.

Copy link
Member

Choose a reason for hiding this comment

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

would any of the current out_of_memory errors ever surface or would the app just be OOM-killed

That's hard to say because I haven't experienced it yet. I don't know what happens with the VM when you try to allocate a term and there is no memory available. Looking at enif_alloc it returns NULL if it fails to allocate.

Initially my target audience for this library was embedded Nerves devices and memory constrained machines running a small elixir application, so it's probably best to figure out a good strategy for handling out of memory. I suspect, probably the best thing to do is to preallocate with the atoms a term or an exception term to return when there is a memory problem. This in theory should not allocate more memory since we would have pre allocated it prior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR: #304

@ruslandoga
Copy link
Contributor Author

Please see #300 (comment)

@ruslandoga ruslandoga closed this Jan 20, 2025
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.

2 participants