Open Bug 1589616 Opened 5 years ago Updated 2 years ago

WebSocket.onMessage is run while paused

Categories

(DevTools :: Debugger, defect, P3)

69 Branch
defect

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.

Forgot to mention - version is 69.0.3.

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.

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Debugger
Product: Firefox → DevTools
Blocks: dbg-r2c
Priority: -- → P2

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

Blocks: dbg-72
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: [debugger] When stopped in a breakpoint FF seems to execute page code on top of that → WebSocket.onMessage is run while paused

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'

I apologize for the bold above - I think something I wrote there was interpreted as markdown styling...

Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.