Hello all,
Since recently, I have issues with websockets … I don’t know what has changed recently?! Maybe the issue was there since a while but I’m pretty sure I would have noticed before. It seems the issue happens more and more often lately!
I have the same issue on at least two versions of Meteor with similar codebase:
One old version METEOR@1.3.2.4
with these DDP packages:
ddp@1.2.5
ddp-client@1.2.7
ddp-common@1.2.5
ddp-server@1.2.6
And also one more recent METEOR@1.4.3.2
with these DDP packages:
ddp@1.2.5
ddp-client@1.3.4
ddp-common@1.2.8
ddp-server@1.3.14
The code base for both is very similar. The installation that is still on 1.3.2.4 hasn’t changed much in the last months (beside some re-builds) and the 1.4.3.2 is the active development branch.
Using Safari on iPad on IOS 10.3.1, I get the following error in the client’s console very repeatedly (3 to 4 times per second for many minutes) – the ID after sockjs changes each time:
WebSocket connection to 'wss://devjf.domain.com/sockjs/599/qj07yo32/websocket' failed: Failed to send WebSocket frame.
doSend — sockjs-0.3.4.js:1292
send — sockjs-0.3.4.js:1222
send — stream_client_sockjs.js:50
_send — livedata_connection.js:1040
sendMessage — livedata_connection.js:433
(anonymous function) — livedata_connection.js:1667
forEach
forEach — underscore.js:149
_sendOutstandingMethods — livedata_connection.js:1666
onReset — livedata_connection.js:354
(anonymous function) — stream_client_sockjs.js:81
forEach
forEach — underscore.js:149
_connected — stream_client_sockjs.js:81
onopen — stream_client_sockjs.js:167
dispatchEvent — sockjs-0.3.4.js:87
_dispatchOpen — sockjs-0.3.4.js:1060
_didMessage — sockjs-0.3.4.js:1125
onmessage — sockjs-0.3.4.js:1277
Then, after 20 minutes, it finally fails for real and the application gets back to its normal state. It gives the following message when it fails for real:
Error invoking Method 'server_AddToFeed': Internal server error [500]
I get the following on my server’s console, in a “catch”:
WriteError({"code":11000,"index":0,"errmsg":"insertDocument :: caused by :: 11000 E11000 duplicate key error index: devjf.Feeds.$_id_ dup key: { : ObjectId('14d580b5edecc4352e54b17e') }","op":{"createdAt":"2017-04-13T21:14:32.037Z","eventType":68,"_id":"14d580b5edecc4352e54b17e"}})
The code from where the problem is triggered is very simple:
try {
Feeds.insert({
createdAt: new Date(),
eventType: pEventNumericalType
});
} catch (error) {
console.log('error inserting feed: ' + error);
}
I do numerous other inserts elsewhere in the code and the issue never happened with the other inserts.
In the duplicate error above, it is true that the inserted _id was a duplicate because it had already been inserted a tenth of a second before the flood of “re-add”. It looks like something is trying to re-add the same database entry over and over (which triggers duplicate detection in MongoDB).
It happens in various environments. On a remotely hosted server (Amazon) over https (wss) but I can also make it bug when connecting on a Meteor running on my laptop over http (ws).
Until I understand what the issue is, I needed to DISABLE_WEBSOCKETS=1
which solved everything …
Anyone has an idea?
Jf.