WebSocket.onMessage is run while paused
Categories
(DevTools :: Debugger, defect, P3)
Tracking
(Not tracked)
People
(Reporter: costescuandrei, Unassigned)
References
(Blocks 1 open bug)
Details
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0
Steps to reproduce:
I was debugging a web page that uses a websocket.
Then it hits a breakpoint and after resuming something that should be impossible happened.
High level pseudocode would be something like:
Websocket.onMessageFromServer calls a function like
var x = undefined;
function myFunc {
try {
x = [];
// do something that has a breakpoint in it - the breakpoint that is hit
// this something could do x.push(...) but not neccesarily
} finally {
// use x assuming it's not undefined; ERROR why is it undefined already here?!
x = undefined;
}
Note that "x" is never assigned to in other place. So as a we page only runs one thread I would expect x to always be defined there.
Actual results:
Turns out the debugger - when it hits a breakpoint - it processes next incomming websocket message on top of it. See below stack trace:
handleMessage http://localhost:8080/sablo/js/websocket.js:199
onmessage http://localhost:8080/sablo/js/websocket.js:687
ReconnectingWebSocket http://localhost:8080/sablo/lib/reconnecting-websocket.js:179
onmessage http://localhost:8080/sablo/lib/reconnecting-websocket.js:280
enter resource://devtools/server/actors/utils/event-loop.js:104
enter self-hosted:1001
_pushThreadPause resource://devtools/server/actors/thread.js:233
_pauseAndRespond resource://devtools/server/actors/thread.js:724
hit resource://devtools/server/actors/breakpoint.js:265
setChangeNotifier http://localhost:8080/servoyservices/foundset_custom_property/foundset.js:517
applyBeanData http://localhost:8080/sablo/js/sablo_app.js:190
getFormMessageHandler http://localhost:8080/sablo/js/sablo_app.js:474
connect http://localhost:8080/sablo/js/sablo_app.js:325
handleMessage http://localhost:8080/sablo/js/websocket.js:279
onmessage http://localhost:8080/sablo/js/websocket.js:687
ReconnectingWebSocket http://localhost:8080/sablo/lib/reconnecting-websocket.js:179
onmessage http://localhost:8080/sablo/lib/reconnecting-websocket.js:280
Expected results:
Hitting a breakpoint should not execute another websocket onMessage on top of current stack; that would never happen without the debugger breakpoint right? The breakpoint was on some simple assignment "internalState.changeNotifier = changeNotifier;" nothing special there.
Reporter | ||
Comment 1•5 years ago
|
||
Forgot to mention - version is 69.0.3.
Reporter | ||
Comment 2•5 years ago
|
||
If you need more information about how the websocket code is set-up let me know.
The same thing debugged in chrome doesn't show this unexpected behavior.
Comment 3•5 years ago
|
||
Bugbug thinks this bug should belong to this component, but please revert this change in case of error.
Comment 4•5 years ago
|
||
Thanks for the report!
Can you please provide a simple test page we could use to reproduce the problem on our machines?
This is usually big help!
Honza
Updated•5 years ago
|
Updated•5 years ago
|
Reporter | ||
Comment 5•5 years ago
|
||
A simple example that shows this (seems to be the same problem):
http://jsfiddle.net/o09grspv/6/
I added a "debugger;" statement in the js code from that fiddle.
To reproduce:
- open browser debug tools
- type "abc" in the "Enter your message to send to the WebSocket server:" field and click on "Send my message to server"
=> debugger will stop execution at the "debugger;" line although it will still print "Message received from server: 'abc'" which shows that socket.onmessage is called while code in "sendMessage" didn't yet finish - it's stopped in a breakpoint. - resume script execution and then you get the "Sent message to server: 'abc'" as well
So the output from when the bug reproduces is this:
Status: Connected!!!
Connected to websocket server at: ws://echo.websocket.org
Message received from server: 'abc'
Sent message to server: 'abc'
If you comment out the debugger; line or if you execute this fiddle in chrome for example (and it too stops at the "debugger;" line) you will get the expected output:
Status: Connected!!!
Connected to websocket server at: ws://echo.websocket.org
Sent message to server: 'abc'
Message received from server: 'abc'
Reporter | ||
Comment 6•5 years ago
|
||
I apologize for the bold above - I think something I wrote there was interpreted as markdown styling...
Updated•4 years ago
|
Updated•2 years ago
|
Description
•