Cleaner crash after running for a while #225
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
java
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
java-gi/java-gi#225
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
It seems like scheduling lots of lambdas to run with
GLib.idleAdd(GLib.PRIORITY_DEFAULT_IDLEcrashes after a while.This crash occurs after about 10 minutes in the given sample code:
Show a crash after about 8k iterations.
The sample code frequently updates a GtkScale to simulate a updating progressbar.
I think I found what's causing the issue!
This is how the process works:
GLib.idleAddcallsg_idle_add_fullfor a SourceFunc parameter (a lambda). The SourceFunc has "notified" scope, i.e. GLib calls a "notify" callback parameter to clean up when the SourceFunc has completed.So far, so good. Now what causes the exception?
g_idle_add_fullreturns.g_idle_add_fullto finish.Arena.close()is called while the allocated upcall stub for the SourceFunc is still being used in a native function call. This is not allowed according to the documentation: "IllegalStateException - if a segment associated with this arena is being accessed concurrently, e.g. by a downcall method handle"I'm not sure yet how to fix this. I don't think there's a way to know, from the "notify" callback, if the call to
g_idle_add_fullhas completed. I'll probably have to catch the exception, sleep for a while, and keep retrying to close the arena until it succeeds.In the meantime, you can work around the issue if you use
GLib.timeoutAddOnce()with a reasonably short timeout parameter. This will allow the call tog_timeout_add_fullto return, before the callback function completes and triggers the IllegalStateException.Even better, replace the entire while-loop with one call to
GLib.timeoutAdd()that runs the entire content of your while-loop every 50 ms.