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

Added synchronization to fix NPE bug in MessageHandler #72

Merged
merged 1 commit into from
Aug 29, 2022
Merged

Added synchronization to fix NPE bug in MessageHandler #72

merged 1 commit into from
Aug 29, 2022

Conversation

mww-aws
Copy link
Contributor

@mww-aws mww-aws commented Aug 27, 2022

MWW, 8/27/2022
This PR fixes an occasional NPE bug that we have seen in jkind in the MessageHandler class. Within the class, the
receiveMessage and stopReceivingMessages methods run on different threads, leading to occasional NPE exceptions due to race conditions when solver is completing analyses.

NPEs happen when incoming is checked for null, but then receiveMessage thread is interrupted and incoming is set to null by stopReceivingMessages prior to incoming.add(message).

Note that other protected functions do not need to be synchronized because they are called on the same thread as stopReceivingMessages.

The fix was tested by running several of the tests in the jkind testing directory looking for possible deadlocks and performance changes. We also ran models that occasionally lead to NPEs that are internal. There is a slight performance hit using synchronized for message passing (a few % of execution, depending on the problem), and no deadlocks occurred. Furthermore, no NPEs were observed.

Tested by running several of the tests in the jkind testing
directory looking for possible deadlocks and performance changes.
There is a slight performance hit using synchronized for message
passing (a few seconds, depending on the problem), and no
deadlocks occurred.
@mww-aws
Copy link
Contributor Author

mww-aws commented Aug 28, 2022

It may be more performant to just add a try/catch block around the incoming.add call to trap NPEs, then check whether incoming is null, but this is also a little bit messier, maintenance-wise, and I'd rather not generate the NPE at all.

@agacek
Copy link
Collaborator

agacek commented Aug 29, 2022

Nice find. Thanks for tracking this down and making the fix.

@agacek agacek merged commit e21d4f2 into loonwerks:master Aug 29, 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.

2 participants