Skip to content

Commit

Permalink
Request Timeouts: Fixup timeout handling.
Browse files Browse the repository at this point in the history
This introduces a new "attention" event that is emitted if we receive
a done token with the attention flag set.

This cleans up the implementation a bit and actually fixes an issue
where we would switch back into the LoggedInState too early because we
did not actually wait for the attention acknowledgement.
  • Loading branch information
arthurschreiber committed Jun 5, 2014
1 parent 0b90f6b commit 09fd8a8
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/connection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,30 @@ class Connection extends EventEmitter

SENT_ATTENTION:
name: 'SentAttention'
enter: ->
@attentionReceived = false
events:
socketError: (error) ->
@transitionTo(@STATE.FINAL)
data: (data) ->
@sendDataToTokenStreamParser(data)
attention: ->
@attentionReceived = true
message: ->
@transitionTo(@STATE.LOGGED_IN)
sqlRequest = @request
@request = undefined
# 3.2.5.7 Sent Attention State
# Discard any data contained in the response, until we receive the attention response
if @attentionReceived
sqlRequest = @request
@request = undefined

@transitionTo(@STATE.LOGGED_IN)

if sqlRequest.canceled
sqlRequest.callback(RequestError("Canceled.", 'ECANCEL'))
else
message = "Timeout: Request failed to complete in #{@config.options.requestTimeout}ms"
sqlRequest.callback(RequestError(message, 'ETIMEOUT'))

if sqlRequest.canceled
sqlRequest.callback(RequestError("Canceled.", 'ECANCEL'))
else
message = "Timeout: Request failed to complete in #{@config.options.requestTimeout}ms"
sqlRequest.callback(RequestError(message, 'ETIMEOUT'))

FINAL:
name: 'Final'
Expand Down Expand Up @@ -333,18 +342,16 @@ class Connection extends EventEmitter
)
@tokenStreamParser.on('done', (token) =>
if @request
# 3.2.5.7 Sent Attention State
# Discard any data contained in the response
if @state == @STATE.SENT_ATTENTION
@request.emit('attention') if token.attention
else
@request.emit('done', token.rowCount, token.more, @request.rows)
if token.attention
@dispatchEvent("attention")

@request.emit('done', token.rowCount, token.more, @request.rows)

if token.rowCount != undefined
@request.rowCount += token.rowCount
if token.rowCount != undefined
@request.rowCount += token.rowCount

if @config.options.rowCollectionOnDone
@request.rows = []
if @config.options.rowCollectionOnDone
@request.rows = []
)
@tokenStreamParser.on('resetConnection', (token) =>
@emit('resetConnection')
Expand Down

0 comments on commit 09fd8a8

Please sign in to comment.