Skip to content

Conversation

@thaystg
Copy link
Member

@thaystg thaystg commented Jul 27, 2022

Session id can be different if there is a redirect, but the message id is kept.

I mean, even if the sessionID number is changed the sequential number that answers the message is the same, so we only need to compare the sequential number.
For example:
We send -> messageID = 1 to sessionID = aaa
We receive -> messageID = 1 sessionID = bbb because there was a redirect
So it was not finding in the dictionary because we were expecting SessionID and MessageId to be the same.
other.sessionId == sessionId && other.id == id;

I have no idea how to create a test case for it.

Fix https://github.com/aspnet/AspNetCore-ManualTests/issues/1456

@thaystg thaystg requested review from ilonatommy and lewing July 27, 2022 17:50
@thaystg thaystg requested a review from radical as a code owner July 27, 2022 17:50
@ghost ghost added the area-Debugger-mono label Jul 27, 2022
@ghost ghost assigned thaystg Jul 27, 2022
@ghost
Copy link

ghost commented Jul 27, 2022

Tagging subscribers to this area: @thaystg
See info in area-owners.md if you want to be subscribed.

Issue Details

Session id can be different if there is a redirect, but the message id is kept.

I mean, even if the sessionID number is changed the sequential number that answers the message is the same, so we only need to compare the sequential number.
For example:
We send -> messageID = 1 to sessionID = aaa
We receive -> messageID = 1 sessionID = bbb because there was a redirect
So it was not finding in the dictionary because we were expecting SessionID and MessageId to be the same.
other.sessionId == sessionId && other.id == id;

I have no idea how to create a test case for it.

Author: thaystg
Assignees: -
Labels:

area-Debugger-mono

Milestone: -

@lewing
Copy link
Member

lewing commented Jul 27, 2022

are the message-ids really unique across all sessions?

@thaystg
Copy link
Member Author

thaystg commented Jul 27, 2022

are the message-ids really unique across all sessions?

It looks like yes.

@lewing
Copy link
Member

lewing commented Jul 27, 2022

is that true for our ids?

@thaystg
Copy link
Member Author

thaystg commented Jul 27, 2022

That is exactly the case that we are getting the message error described in the issue, we are sending messageID=259, and the session does not exist anymore, so we receive an answer with messageID=259 and another sessionID, that is why we weren't find it.

Where we increment:

protected int GetNewCmdId() => Interlocked.Increment(ref next_cmd_id);

Where we use it:

This is only reset on firefox when we connect to the page, on chrome it's never reset.

@radical
Copy link
Member

radical commented Jul 27, 2022

Session id can be different if there is a redirect, but the message id is kept.

What do you mean by a "redirect" here?

@ilonatommy
Copy link
Member

I have no idea how to create a test case for it.

When it was observed? This link to issue does not work, could you check it?

@thaystg
Copy link
Member Author

thaystg commented Jul 28, 2022

I have no idea how to create a test case for it.

When it was observed? This link to issue does not work, could you check it?

It looks like you don't have rights to see it, I already asked for, let's wait.

@thaystg
Copy link
Member Author

thaystg commented Jul 28, 2022

Session id can be different if there is a redirect, but the message id is kept.

What do you mean by a "redirect" here?

Something like go to a login page and login.

@radical radical added the arch-wasm WebAssembly architecture label Jul 28, 2022
@ghost
Copy link

ghost commented Jul 28, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Session id can be different if there is a redirect, but the message id is kept.

I mean, even if the sessionID number is changed the sequential number that answers the message is the same, so we only need to compare the sequential number.
For example:
We send -> messageID = 1 to sessionID = aaa
We receive -> messageID = 1 sessionID = bbb because there was a redirect
So it was not finding in the dictionary because we were expecting SessionID and MessageId to be the same.
other.sessionId == sessionId && other.id == id;

I have no idea how to create a test case for it.

Fix https://github.com/aspnet/AspNetCore-ManualTests/issues/1456

Author: thaystg
Assignees: thaystg
Labels:

arch-wasm, area-Debugger-mono

Milestone: -

@radical radical added this to the 7.0.0 milestone Jul 28, 2022
@lewing
Copy link
Member

lewing commented Jul 28, 2022

This still doesn't seem correct to me (not to mention we'd need to change the hash computation) based on the error in the linked issue my guess is that we're comparing one message with a string.Empty sessionId to another with a null one. Can you changing the MessageId constructor to do:

        this.sessionId = string.IsNullOrEmpty (sessionId) ? null : sessionId;

Copy link
Member

@lewing lewing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this would fix the dictionary lookup in the general case. We need to make sure the hash code and Equals use the same logic

@ghost ghost added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jul 29, 2022
@thaystg
Copy link
Member Author

thaystg commented Jul 29, 2022

This still doesn't seem correct to me (not to mention we'd need to change the hash computation) based on the error in the linked issue my guess is that we're comparing one message with a string.Empty sessionId to another with a null one. Can you changing the MessageId constructor to do:

        this.sessionId = string.IsNullOrEmpty (sessionId) ? null : sessionId;

This is exactly what we are comparing:

see the pending_cmds
SessionId = FD9F77A4C958D595651B0F5D39AC75AC - CommandId = 277
SessionId = 469F7AE3DF255CC5FC81CF5BEF2B7523 - CommandId = 278
SessionId = FD9F77A4C958D595651B0F5D39AC75AC - CommandId = 276
SessionId = FD9F77A4C958D595651B0F5D39AC75AC - CommandId = 275
I was looking for: SessionId =  - CommandId = 276
see the pending_cmds
SessionId = FD9F77A4C958D595651B0F5D39AC75AC - CommandId = 277
SessionId = 469F7AE3DF255CC5FC81CF5BEF2B7523 - CommandId = 278
SessionId = FD9F77A4C958D595651B0F5D39AC75AC - CommandId = 276
SessionId = FD9F77A4C958D595651B0F5D39AC75AC - CommandId = 275
I was looking for: SessionId =  - CommandId = 277

So to be clear, we are sending command 276 from sessionID FD9F77A4C958D595651B0F5D39AC75AC and receiving the answer from SessionId = "";
We are sending command 277 from sessionID FD9F77A4C958D595651B0F5D39AC75AC and also receiving the answer from SessionId = "";

So I agree we need to change the hash, but I don't think that considering an empty string as NULL will fix it.

@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Jul 29, 2022
@thaystg
Copy link
Member Author

thaystg commented Jul 29, 2022

I don't see how this would fix the dictionary lookup in the general case. We need to make sure the hash code and Equals use the same logic

After testing more and more, I detected that this is not always happening, it only happens sometimes, but I'm confident that the fix works because I added a message in the code like this:
image

And I ran a lot of times until see the "we would get the error" message.

Also after a lot of tests I got an error when we receive and send the Debugger.Enabled message, same error "Session with given id not found", so I also protected that message.

@lewing
Copy link
Member

lewing commented Jul 29, 2022

iirc a missing sessionId means it applies to all sessions so it makes more sense than a different sessionId. The updates look fine although it might make sense to warn if the sessions have a value and are different because I don't think that should ever happen. What command is the response to?

@thaystg
Copy link
Member Author

thaystg commented Jul 29, 2022

iirc a missing sessionId means it applies to all sessions so it makes more sense than a different sessionId. The updates look fine although it might make sense to warn if the sessions have a value and are different because I don't think that should ever happen. What command is the response to?

{
  "id": 536,
  "method": "Debugger.enable",
  "params": {},
  "sessionId": "EDA0856A52259CB6A25FDCB8A6282422"
}

{
  "id": 537,
  "method": "Runtime.evaluate",
  "params": {
    "expression": "getDotnetRuntime(0).INTERNAL.mono_wasm_runtime_is_ready",
    "objectGroup": "mono-debugger",
    "includeCommandLineAPI": false,
    "silent": false,
    "returnByValue": true
  },
  "sessionId": "EDA0856A52259CB6A25FDCB8A6282422"
}

@lewing lewing merged commit 3ab1fd0 into dotnet:main Aug 15, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture area-Debugger-mono

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants