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 serialization tests & don't block thread #846

Merged
merged 4 commits into from
Aug 9, 2019

Conversation

kevcunnane
Copy link
Contributor

  • Fixed potential null ref when closing streams
  • Always clean up serialization queue if an error occurs
  • Stop blocking dispatcher thread by not awaiting task that processes the message
  • Improved error logging in EventFlowValidator to help debug issues

My hope is this will result in the tests reliably passing now.
Will monitor in GCI to verify

- Fixed potential null ref when closing streams
- Always clean up serialization queue if an error occurs
- Stop blocking dispatcher thread by not awaiting task that processes the message
- Improved error logging in EventFlowValidator to help debug issues

My hope is this will result in the tests reliably passing now.
Will monitor in GCI to verify
@alanrenmsft alanrenmsft removed their assignment Aug 8, 2019
@alanrenmsft alanrenmsft self-requested a review August 8, 2019 22:17
}
catch
{
// Do not care if there was an error removing this, must always delete if something failed
Copy link
Contributor

Choose a reason for hiding this comment

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

must always delete if something failed [](start = 72, length = 38)

You're not actually deleting the file though - is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great question. I have a gap here for sure. On consideration, I will ensure the write stream is closed out in this case and intentionally leave file contents that have been written as-is. The thinking is that for most formats (CSV, JSON) users are going to be happier with half the written contents on an unexpected error than none.

@alanrenmsft
Copy link
Contributor

Charles pointed out that you are not actually deleting the file, looks good other than that.

// Run in separate thread so that message thread isn't held up by a potentially time consuming file write
Task.Run(async () => {
await RunSerializeStartRequest(serializeParams, requestContext);
}).ContinueWithOnFaulted(async t => await SendErrorAndCleanup(serializeParams?.FilePath, requestContext, t.Exception));
Copy link
Contributor

Choose a reason for hiding this comment

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

So a potential problem is that now since this is truly async we'll immediately return - at which point the caller may then call to continue serialization. But the start request may not actually have started/finished yet and thus we have a race condition if the continue serialization call starts trying to do stuff assuming that the start request has finished.

Same issue with the continue calls - those could then get out of order or start causing problems trying to write at the same time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, this is dependent on the caller waiting on responses. That's what I've implemented in ADS - we wait on the result to come back, then send the next request. Since each one is awaited, we will get correct ordering. Right now I would treat this as "by design" because:

  • the cost to implement differently would be a lot higher since you then need an ordered queue model to track
  • most importantly since we're sending potentially large amounts of data, all of which are kept in memory until serialized, I explicitly do not want to encourage "send 5 messages in a row" and instead require "send message, wait until processed, send next message".

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right, yeah my mistake. Got confused about the return value here being the indication that the request was done. Nevermind!

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest leaving a comment in the code about this stated 'by design' contract.

@ranasaria
Copy link
Contributor

ranasaria commented Aug 8, 2019 via email

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 76.424% when pulling 3334215 on fix/serializationTests into 8d7acab on master.

@kevcunnane kevcunnane merged commit d42e362 into master Aug 9, 2019
@kevcunnane kevcunnane deleted the fix/serializationTests branch August 9, 2019 16:49
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.

None yet

5 participants