Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public override async Task ProcessCommand(Result command, CancellationToken toke
return null;

var messageId = new FirefoxMessageId("", 0, from_str);
if (pending_cmds.Remove(messageId, out var item))
if (pending_cmds.TryRemove(messageId, out var item))
item.SetResult(Result.FromJsonFirefox(res));
else
logger.LogDebug($"HandleMessage: Could not find any pending cmd for {messageId}. msg: {msg}");
Expand All @@ -156,7 +156,7 @@ public override async Task ProcessCommand(Result command, CancellationToken toke
return null;

var messageId = new FirefoxMessageId("", 0, from_str);
if (pending_cmds.Remove(messageId, out var item))
if (pending_cmds.TryRemove(messageId, out var item))
{
item.SetResult(Result.FromJsonFirefox(res));
return null;
Expand Down Expand Up @@ -234,8 +234,7 @@ public override Task<Result> SendCommand(SessionId sessionId, string method, JOb
throw new Exception($"No 'to' field found in '{args}'");

msgId = new FirefoxMessageId("", 0, to_str);
pending_cmds[msgId] = tcs;
logger.LogTrace($"SendCommand: to: {args}");
pending_cmds.AddOrUpdate(msgId, tcs, (key, oldValue) => tcs);

var msg = args.ToString(Formatting.None);
var bytes = Encoding.UTF8.GetBytes(msg);
Expand Down
10 changes: 6 additions & 4 deletions src/mono/wasm/debugger/DebuggerTestSuite/InspectorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Net;
using System.Net.Sockets;
using System.Net.WebSockets;
Expand All @@ -17,7 +17,7 @@ namespace DebuggerTests
{
internal class InspectorClient : DevToolsClient
{
protected Dictionary<MessageId, TaskCompletionSource<Result>> pending_cmds = new Dictionary<MessageId, TaskCompletionSource<Result>>();
protected readonly ConcurrentDictionary<MessageId, TaskCompletionSource<Result>> pending_cmds = new();
protected Func<string, string, JObject, CancellationToken, Task> onEvent;
protected int next_cmd_id;

Expand All @@ -39,7 +39,7 @@ protected virtual Task HandleMessage(string msg, CancellationToken token)
return onEvent(res["sessionId"]?.Value<string>(), res["method"].Value<string>(), res["params"] as JObject, token);

var id = res.ToObject<MessageId>();
if (!pending_cmds.Remove(id, out var item))
if (!pending_cmds.TryRemove(id, out var item))
logger.LogError($"Unable to find command {id}");

item.SetResult(Result.FromJson(res));
Expand Down Expand Up @@ -95,7 +95,9 @@ public virtual Task<Result> SendCommand(SessionId sessionId, string method, JObj
if (sessionId != SessionId.Null)
o.Add("sessionId", sessionId.sessionId);
var tcs = new TaskCompletionSource<Result>();
pending_cmds[new MessageId(sessionId.sessionId, id)] = tcs;

MessageId msgId = new MessageId(sessionId.sessionId, id);
pending_cmds.AddOrUpdate(msgId, tcs, (key, oldValue) => tcs);

var str = o.ToString();

Expand Down