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

Wip Pr for thread safety #276

Closed
wants to merge 8 commits into from
Closed

Conversation

Rohith-Raju
Copy link
Contributor

@gavv
Copy link
Owner

gavv commented Feb 4, 2023

I suggest the following implementation:

  • make c.failure a pointer
  • in chain.fail set this pointer
  • in chain.leave, in the block under a lock, read c.context, c.handler, c.failure and c.flags into local variables
  • in chain.leave, after releasing the lock, do this:
    • if flagFailed is set, and failure is non nil, report it to handler
    • if flagFailed or flagFailedChildren is set, propagate failure to parents (that's what currently is done if reportFailure boolean is true)
    • if none of these flags are set, report success to handler
  • boolean flags reportSuccess and reportFailure can be removed
  • we need a test for chain, which uses mock AssertionHandler and checks that fail does not report failure and instead leave reports it

@gavv gavv added the work in progress Pull request is still in progress and changing label Feb 4, 2023
@gavv gavv force-pushed the master branch 5 times, most recently from d159043 to 7d9207b Compare February 4, 2023 11:47
Signed-off-by: ROHITH RAJU <rohithraju488@gmail.com>
Signed-off-by: ROHITH RAJU <rohithraju488@gmail.com>
Signed-off-by: ROHITH RAJU <rohithraju488@gmail.com>
Signed-off-by: ROHITH RAJU <rohithraju488@gmail.com>
Signed-off-by: ROHITH RAJU <rohithraju488@gmail.com>
Signed-off-by: ROHITH RAJU <rohithraju488@gmail.com>
Signed-off-by: ROHITH RAJU <rohithraju488@gmail.com>
Signed-off-by: ROHITH RAJU <rohithraju488@gmail.com>
@coveralls
Copy link
Collaborator

coveralls commented Feb 5, 2023

Coverage Status

Coverage: 94.925% (+0.02%) from 94.903% when pulling f5c024e on Rohith-Raju:dummy_pr into 015196a on gavv:master.

@Rohith-Raju
Copy link
Contributor Author

  • we need a test for chain, which uses mock AssertionHandler and checks that fail does not report failure and instead leave reports it

This is for the coverage right?.. Ill do it

@gavv
Copy link
Owner

gavv commented Feb 5, 2023

  • we need a test for chain, which uses mock AssertionHandler and checks that fail does not report failure and instead leave reports it

This is for the coverage right?.. Ill do it

This is important part of contract - other code will rely on fact that AssertionHandler is called in leave(), not in fail(). So it's important to fix this contract in test.

@Rohith-Raju
Copy link
Contributor Author

This is important part of contract - other code will rely on fact that AssertionHandler is called in leave(), not in fail(). So it's important to fix this contract in test.

Yes, this makes sense

@Rohith-Raju
Copy link
Contributor Author

Rohith-Raju commented Feb 5, 2023

@gavv
So by doing these changes in c83c252 where I went wrong was that I reported handler when parent chain was locked and that blocked me out. Now f5c024e we are first releasing the lock and then reporting which is allowed. Is this analysis right? am I missing something?

@gavv
Copy link
Owner

gavv commented Feb 5, 2023

@Rohith-Raju

The current code is still broken and looks like you ignored explanations (in chat) and suggestions (here in PR) or didn't read them carefully...

You're writing c.failure outside of the lock. You're then reading several chain fields into local vars outside of the lock too. This is a data race. Note: I'm talking about chain's lock here, not about parent's lock. Also, as I mentioned, it's better to get rid of reportSuccess and reportFailure. Also, as I also mentioned, PR currently contains some unrelated renames, it's make reviewing a bit harder, please rollback that. Yeah, also this is not a correct way to check if flag is set: flags&flagFailed == 1.

@Rohith-Raju
Copy link
Contributor Author

ok will take a good look into it

@Rohith-Raju Rohith-Raju closed this Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work in progress Pull request is still in progress and changing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants