Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a4190f

Browse files
committed
Fix issue: reconnection only happends for 1 time after connection drops
Since the PR#125 fixed duplicate connections after reconnection by using a `connectionInProgress` lock to avoid function `connect()` be called duplicately.But it forgot to release the `connectionInProgress` lock when request error happends, in that case, our client can only retry for 1 time and never get the lock again.So it's needed to release the `connectionInProgress` lock when error happends.Signed-off-by: icy_fish <keith519@qq.com>
1 parent61e1b19 commit9a4190f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

‎lib/eventsource.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ function EventSource (url, eventSourceInitDict) {
242242
})
243243

244244
req.on('error',function(err){
245+
self.connectionInProgress=false
245246
onConnectionClosed(err.message)
246247
})
247248

‎test/eventsource_test.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,34 @@ describe('Reconnection', function () {
710710
}
711711
})
712712

713+
it('continuing attempts when server is down',function(done){
714+
// Seems set reconnectInterval=0 not work here, this makes total time spent for current case more than 3S
715+
this.timeout(4000)
716+
717+
vares=newEventSource('http://localhost:'+_port++)
718+
es.reconnectInterval=0
719+
varreconnectCount=0
720+
721+
es.onerror=function(){
722+
reconnectCount++
723+
// make sure client is keeping reconnecting
724+
if(reconnectCount>2){
725+
es.onerror=null
726+
varport=u.parse(es.url).port
727+
configureServer(http.createServer(),'http',port,function(err,server){
728+
if(err)returndone(err)
729+
730+
server.on('request',writeEvents(['data: hello\n\n']))
731+
732+
es.onmessage=function(m){
733+
assert.equal('hello',m.data)
734+
server.close(done)
735+
}
736+
})
737+
}
738+
}
739+
})
740+
713741
it('is attempted when server goes down after connection',function(done){
714742
createServer(function(err,server){
715743
if(err)returndone(err)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp