Skip to content

Commit b4fbe8d

Browse files
committed
missed a sync-context await
1 parent 51079ec commit b4fbe8d

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

src/StackExchange.Redis/PhysicalConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static Socket CreateSocket(EndPoint endpoint)
233233
// If we're told to ignore connect, abort here
234234
if (BridgeCouldBeNull?.Multiplexer?.IgnoreConnect ?? false) return;
235235

236-
await pendingConnect; // wait for the connect to complete or fail (will throw)
236+
await pendingConnect.ForAwait(); // wait for the connect to complete or fail (will throw)
237237
DiscardTimeout(ref timeoutSource);
238238

239239
socket = VolatileSocket;

tests/StackExchange.Redis.Tests/SyncContextTests.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
4+
using System.Text;
35
using System.Threading;
46
using System.Threading.Tasks;
57
using Xunit;
68

79
namespace StackExchange.Redis.Tests
810
{
11+
[RunPerProtocol]
912
public class SyncContextTests(ITestOutputHelper testOutput) : TestBase(testOutput)
1013
{
1114
/* Note A (referenced below)
@@ -72,6 +75,7 @@ public async Task SyncConfigure()
7275
using var ctx = new MySyncContext(Writer);
7376
await using var conn = Create();
7477
Assert.Equal(0, ctx.OpCount);
78+
// ReSharper disable once MethodHasAsyncOverload - very deliberate
7579
Assert.True(conn.Configure());
7680
Assert.Equal(0, ctx.OpCount);
7781
}
@@ -130,7 +134,7 @@ public MySyncContext(TextWriter log)
130134

131135
public override void Post(SendOrPostCallback d, object? state)
132136
{
133-
Log(_log, "sync-ctx: Post");
137+
Log(_log, $"sync-ctx: Post {Format(d, state)}");
134138
Incr();
135139
ThreadPool.QueueUserWorkItem(
136140
static state =>
@@ -143,14 +147,32 @@ public override void Post(SendOrPostCallback d, object? state)
143147

144148
private void Invoke(SendOrPostCallback d, object? state)
145149
{
146-
Log(_log, "sync-ctx: Invoke");
150+
Log(_log, $"sync-ctx: Invoke {Format(d, state)}");
147151
if (!IsCurrent) SetSynchronizationContext(this);
148152
d(state);
149153
}
150154

155+
private static string Format(SendOrPostCallback? d, object? state)
156+
{
157+
if (d is null) return "";
158+
string name = d.IsSingle() ? d.Method.Name : GetNames(d);
159+
return state is null ? name : $"{name}:{state}";
160+
161+
static string GetNames(SendOrPostCallback d)
162+
{
163+
var sb = new StringBuilder();
164+
foreach (var x in d.AsEnumerable())
165+
{
166+
if (sb.Length != 0) sb.Append(",");
167+
sb.Append(x.Method.Name);
168+
}
169+
return sb.ToString();
170+
}
171+
}
172+
151173
public override void Send(SendOrPostCallback d, object? state)
152174
{
153-
Log(_log, "sync-ctx: Send");
175+
Log(_log, $"sync-ctx: Send {Format(d, state)}");
154176
Incr();
155177
Invoke(d, state);
156178
}

0 commit comments

Comments
 (0)