Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

potential delay between recieving a response and firing event hooks #285

Open

Description

@blampe

I'm skeptical of the events we're seeing reported. Right now response logic looks like this:

response_future = connection.send_request(req)

with timeout(response_future, req.ttl):
    try:
        response = yield response_future
    except TChannelError as error:
        # event: after_receive_error
        self.tchannel.event_emitter.fire(
            EventType.after_receive_error, req, error,
        )
        raise
# event: after_receive_response
self.tchannel.event_emitter.fire(
    EventType.after_receive_response, req, response,
)

I'm pretty sure this is wrong because the yield statement isn't guaranteed to resume immediately after the future resolves, so there's potential for delay between receiving a response and firing the after_receive_response event for it.

More correct (I think) would be this:

response_future = connection.send_request(req)

def fire_events(f):
    if f.exception():
        self.tchannel.event_emitter.fire(
            EventType.after_receive_error, req, error,
        )
        raise f.exception()
    self.tchannel.event_emitter.fire(
        EventType.after_receive_response, req, response,
    )

response_future.add_done_callback(fire_events)

with timeout(response_future, req.ttl):
        yield response_future

because add_done_callback is preemptive and will execute as soon as the future resolves.

Activity

  1. jc-fireball commented on Nov 3, 2015

    @jc-fireball
    Contributor

    It's true the sequence of callback is add_done_callback > add_future > yield

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions