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

wakeup-cleanup: only allow one wakeup calblack per I/O operation #161

Merged
merged 1 commit into from
Jan 13, 2020

Conversation

seliopou
Copy link
Member

Cleanup wakeup callback bookkeeping that got a bit hairy as a result of #158. Body only allows a single wakeup callback to be registered with it, so just propagate that constraint up to the server connection layer.

@seliopou seliopou requested a review from dpatti October 18, 2019 02:32
@dpatti dpatti merged commit 75e057f into master Jan 13, 2020
@dpatti dpatti deleted the wakeup-cleanup branch January 13, 2020 00:58
anmonteiro added a commit to anmonteiro/httpun that referenced this pull request Jan 22, 2020
bookkeeping to be wrong for async responses

Introduced in inhabitedtype/httpaf#161
anmonteiro added a commit to anmonteiro/httpun that referenced this pull request Jan 22, 2020
dakotamurphyucf added a commit to chattyzilla-labs/zillaml that referenced this pull request Jan 26, 2020
  [inhabitedtype/httpaf#161](inhabitedtype/httpaf#161)
  that caused `wake_up_writer` callback bookkeeping to be slightly wrong due to
  physical equality, producing runtime errors in cases where it shouldn't
  ([#37](anmonteiro/httpun#37)).
@Lupus
Copy link
Contributor

Lupus commented Apr 2, 2020

@seliopou @dpatti This PR seems to introduce a regression, starting from it's merge point and up to latest master (d22250e as of now) tests of our in-house framework build on top of httpaf hang. I've looked at test that hangs, it does not seem to do anything complicated, creates http server with handler, serving json payload, and a client which requests it (both built on httpaf).

@seliopou
Copy link
Member Author

seliopou commented Apr 2, 2020 via email

@seliopou
Copy link
Member Author

seliopou commented Apr 2, 2020

Doug and I took a look at this and think we know the cause of it.

@Lupus Lupus mentioned this pull request Apr 3, 2020
@dpatti
Copy link
Collaborator

dpatti commented Apr 4, 2020

Some context on what was going on here for the record: one subtle change introduced in this PR is that we always transfer the writer callback to Reqd , even if it's empty. The specific situation that could occur is:

  1. You have not started the write loop and thus haven't yielded for the first time
  2. The read loop finishes and the default (noop) thunk was transferred to the Reqd
  3. The write loop starts and immediately yields, also transferring to the Reqd

That third step caused an exception because there was already a callback registered. I'm curious @Lupus if your httpaf runtime was actually raising an exception inside the write loop but it was somehow being swallowed, so it appeared as though the request was just hanging.

I also believe that if the write loop is started before the read loop, this would not happen because in step two we'd be transferring a real callback and wouldn't have an issue of callbacks colliding. I think this is why we never noticed this in practice.

The fix of introducing the optional thunk was both a nice refactor to pull a common pattern out of three modules, and it made it more clear that we shouldn't pass a none thunk to another module (though actually, now that the concept of none is centralized, even if we mistakenly transferred it to Reqd, it wouldn't have caused an issue in this situation).

@Lupus
Copy link
Contributor

Lupus commented Apr 5, 2020

Thanks for the details @dpatti !

We've been tweaking exceptions in our Lwt adapter fork, I don't recall the details but we recently tried pinning httpaf to latest master in one of our services (but before this regression was fixed) and got this error:

Request reply exception: (Failure
  "httpaf.Reqd.respond_with_streaming: invalid state, currently handling error")

Looks like it might be related.

anmonteiro added a commit to anmonteiro/httpun that referenced this pull request May 11, 2020
anmonteiro added a commit to anmonteiro/httpun that referenced this pull request May 11, 2020
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.

3 participants