Skip to content

Commit 3561949

Browse files
Rename internal UseAck to UseStatefulReconnect (#50407)
1 parent cde7cb4 commit 3561949

File tree

14 files changed

+73
-74
lines changed

14 files changed

+73
-74
lines changed

src/SignalR/clients/csharp/Client/test/UnitTests/TestTransportFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public TestTransportFactory(ITransport transport)
1515
_transport = transport;
1616
}
1717

18-
public ITransport CreateTransport(HttpTransportType availableServerTransports, bool useAck)
18+
public ITransport CreateTransport(HttpTransportType availableServerTransports, bool useStatefulReconnect)
1919
{
2020
return _transport;
2121
}

src/SignalR/clients/csharp/Http.Connections.Client/src/HttpConnection.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ private async Task SelectAndStartTransport(TransferFormat transferFormat, Cancel
313313
if (_httpConnectionOptions.Transports == HttpTransportType.WebSockets)
314314
{
315315
Log.StartingTransport(_logger, _httpConnectionOptions.Transports, uri);
316-
await StartTransport(uri, _httpConnectionOptions.Transports, transferFormat, cancellationToken, useAck: false).ConfigureAwait(false);
316+
await StartTransport(uri, _httpConnectionOptions.Transports, transferFormat, cancellationToken, useStatefulReconnect: false).ConfigureAwait(false);
317317
}
318318
else
319319
{
@@ -459,7 +459,7 @@ private async Task<NegotiationResponse> NegotiateAsync(Uri url, HttpClient httpC
459459

460460
if (_httpConnectionOptions.UseStatefulReconnect)
461461
{
462-
uri = Utils.AppendQueryString(uri, "useAck=true");
462+
uri = Utils.AppendQueryString(uri, "useStatefulReconnect=true");
463463
}
464464

465465
using (var request = new HttpRequestMessage(HttpMethod.Post, uri))
@@ -507,10 +507,11 @@ private static Uri CreateConnectUrl(Uri url, string? connectionId)
507507
return Utils.AppendQueryString(url, $"id={connectionId}");
508508
}
509509

510-
private async Task StartTransport(Uri connectUrl, HttpTransportType transportType, TransferFormat transferFormat, CancellationToken cancellationToken, bool useAck)
510+
private async Task StartTransport(Uri connectUrl, HttpTransportType transportType, TransferFormat transferFormat,
511+
CancellationToken cancellationToken, bool useStatefulReconnect)
511512
{
512513
// Construct the transport
513-
var transport = _transportFactory.CreateTransport(transportType, useAck);
514+
var transport = _transportFactory.CreateTransport(transportType, useStatefulReconnect);
514515

515516
// Start the transport, giving it one end of the pipe
516517
try
@@ -531,7 +532,7 @@ private async Task StartTransport(Uri connectUrl, HttpTransportType transportTyp
531532
// We successfully started, set the transport properties (we don't want to set these until the transport is definitely running).
532533
_transport = transport;
533534

534-
if (useAck && _transport is IStatefulReconnectFeature reconnectFeature)
535+
if (useStatefulReconnect && _transport is IStatefulReconnectFeature reconnectFeature)
535536
{
536537
#pragma warning disable CA2252 // This API requires opting into preview features
537538
Features.Set(reconnectFeature);

src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/DefaultTransportFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public DefaultTransportFactory(HttpTransportType requestedTransportType, ILogger
3131
_accessTokenProvider = accessTokenProvider;
3232
}
3333

34-
public ITransport CreateTransport(HttpTransportType availableServerTransports, bool useAck)
34+
public ITransport CreateTransport(HttpTransportType availableServerTransports, bool useStatefulReconnect)
3535
{
3636
if (_websocketsSupported && (availableServerTransports & HttpTransportType.WebSockets & _requestedTransportType) == HttpTransportType.WebSockets)
3737
{
3838
try
3939
{
40-
return new WebSocketsTransport(_httpConnectionOptions, _loggerFactory, _accessTokenProvider, _httpClient, useAck);
40+
return new WebSocketsTransport(_httpConnectionOptions, _loggerFactory, _accessTokenProvider, _httpClient, useStatefulReconnect);
4141
}
4242
catch (PlatformNotSupportedException ex)
4343
{
@@ -49,13 +49,13 @@ public ITransport CreateTransport(HttpTransportType availableServerTransports, b
4949
if ((availableServerTransports & HttpTransportType.ServerSentEvents & _requestedTransportType) == HttpTransportType.ServerSentEvents)
5050
{
5151
// We don't need to give the transport the accessTokenProvider because the HttpClient has a message handler that does the work for us.
52-
return new ServerSentEventsTransport(_httpClient!, _httpConnectionOptions, _loggerFactory, useAck);
52+
return new ServerSentEventsTransport(_httpClient!, _httpConnectionOptions, _loggerFactory);
5353
}
5454

5555
if ((availableServerTransports & HttpTransportType.LongPolling & _requestedTransportType) == HttpTransportType.LongPolling)
5656
{
5757
// We don't need to give the transport the accessTokenProvider because the HttpClient has a message handler that does the work for us.
58-
return new LongPollingTransport(_httpClient!, _httpConnectionOptions, _loggerFactory, useAck);
58+
return new LongPollingTransport(_httpClient!, _httpConnectionOptions, _loggerFactory);
5959
}
6060

6161
throw new InvalidOperationException("No requested transports available on the server.");

src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/ITransportFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ namespace Microsoft.AspNetCore.Http.Connections.Client.Internal;
55

66
internal interface ITransportFactory
77
{
8-
ITransport CreateTransport(HttpTransportType availableServerTransports, bool useAck);
8+
ITransport CreateTransport(HttpTransportType availableServerTransports, bool useStatefulReconnect);
99
}

src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/LongPollingTransport.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ internal sealed partial class LongPollingTransport : ITransport
1919
private readonly HttpClient _httpClient;
2020
private readonly ILogger _logger;
2121
private readonly HttpConnectionOptions _httpConnectionOptions;
22-
private readonly bool _useAck;
2322
private IDuplexPipe? _application;
2423
private IDuplexPipe? _transport;
2524
// Volatile so that the poll loop sees the updated value set from a different thread
@@ -33,12 +32,11 @@ internal sealed partial class LongPollingTransport : ITransport
3332

3433
public PipeWriter Output => _transport!.Output;
3534

36-
public LongPollingTransport(HttpClient httpClient, HttpConnectionOptions? httpConnectionOptions = null, ILoggerFactory? loggerFactory = null, bool useAck = false)
35+
public LongPollingTransport(HttpClient httpClient, HttpConnectionOptions? httpConnectionOptions = null, ILoggerFactory? loggerFactory = null)
3736
{
3837
_httpClient = httpClient;
3938
_logger = (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger<LongPollingTransport>();
4039
_httpConnectionOptions = httpConnectionOptions ?? new();
41-
_useAck = useAck;
4240
}
4341

4442
public async Task StartAsync(Uri url, TransferFormat transferFormat, CancellationToken cancellationToken = default)

src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/ServerSentEventsTransport.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ internal sealed partial class ServerSentEventsTransport : ITransport
2626
private readonly CancellationTokenSource _transportCts = new CancellationTokenSource();
2727
private readonly CancellationTokenSource _inputCts = new CancellationTokenSource();
2828
private readonly ServerSentEventsMessageParser _parser = new ServerSentEventsMessageParser();
29-
private readonly bool _useAck;
3029
private IDuplexPipe? _transport;
3130
private IDuplexPipe? _application;
3231

@@ -36,11 +35,10 @@ internal sealed partial class ServerSentEventsTransport : ITransport
3635

3736
public PipeWriter Output => _transport!.Output;
3837

39-
public ServerSentEventsTransport(HttpClient httpClient, HttpConnectionOptions? httpConnectionOptions = null, ILoggerFactory? loggerFactory = null, bool useAck = false)
38+
public ServerSentEventsTransport(HttpClient httpClient, HttpConnectionOptions? httpConnectionOptions = null, ILoggerFactory? loggerFactory = null)
4039
{
4140
ArgumentNullThrowHelper.ThrowIfNull(httpClient);
4241

43-
_useAck = useAck;
4442
_httpClient = httpClient;
4543
_logger = (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger<ServerSentEventsTransport>();
4644
_httpConnectionOptions = httpConnectionOptions ?? new();

src/SignalR/clients/ts/signalr/src/HttpConnection.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface INegotiateResponse {
3131
url?: string;
3232
accessToken?: string;
3333
error?: string;
34-
useAck?: boolean;
34+
useStatefulReconnect?: boolean;
3535
}
3636

3737
/** @private */
@@ -333,7 +333,7 @@ export class HttpConnection implements IConnection {
333333
negotiateResponse.connectionToken = negotiateResponse.connectionId;
334334
}
335335

336-
if (negotiateResponse.useAck && this._options._useStatefulReconnect !== true) {
336+
if (negotiateResponse.useStatefulReconnect && this._options._useStatefulReconnect !== true) {
337337
return Promise.reject(new FailedToNegotiateWithServerError("Client didn't negotiate Stateful Reconnect but the server did."));
338338
}
339339

@@ -374,7 +374,8 @@ export class HttpConnection implements IConnection {
374374
const transports = negotiateResponse.availableTransports || [];
375375
let negotiate: INegotiateResponse | undefined = negotiateResponse;
376376
for (const endpoint of transports) {
377-
const transportOrError = this._resolveTransportOrError(endpoint, requestedTransport, requestedTransferFormat, negotiate?.useAck === true);
377+
const transportOrError = this._resolveTransportOrError(endpoint, requestedTransport, requestedTransferFormat,
378+
negotiate?.useStatefulReconnect === true);
378379
if (transportOrError instanceof Error) {
379380
// Store the error and continue, we don't want to cause a re-negotiate in these cases
380381
transportExceptions.push(`${endpoint.transport} failed:`);
@@ -438,7 +439,7 @@ export class HttpConnection implements IConnection {
438439
if (this.features.reconnect) {
439440
this.transport!.onclose = async (e) => {
440441
let callStop = false;
441-
if (this.features.resend) {
442+
if (this.features.reconnect) {
442443
try {
443444
this.features.disconnected();
444445
await this.transport!.connect(url, transferFormat);
@@ -462,7 +463,7 @@ export class HttpConnection implements IConnection {
462463
}
463464

464465
private _resolveTransportOrError(endpoint: IAvailableTransport, requestedTransport: HttpTransportType | undefined,
465-
requestedTransferFormat: TransferFormat, useAcks: boolean): ITransport | Error | unknown {
466+
requestedTransferFormat: TransferFormat, useStatefulReconnect: boolean): ITransport | Error | unknown {
466467
const transport = HttpTransportType[endpoint.transport];
467468
if (transport === null || transport === undefined) {
468469
this._logger.log(LogLevel.Debug, `Skipping transport '${endpoint.transport}' because it is not supported by this client.`);
@@ -478,7 +479,7 @@ export class HttpConnection implements IConnection {
478479
} else {
479480
this._logger.log(LogLevel.Debug, `Selecting transport '${HttpTransportType[transport]}'.`);
480481
try {
481-
this.features.reconnect = transport === HttpTransportType.WebSockets ? useAcks : undefined;
482+
this.features.reconnect = transport === HttpTransportType.WebSockets ? useStatefulReconnect : undefined;
482483
return this._constructTransport(transport);
483484
} catch (ex) {
484485
return ex;
@@ -588,12 +589,12 @@ export class HttpConnection implements IConnection {
588589
searchParams.append("negotiateVersion", this._negotiateVersion.toString());
589590
}
590591

591-
if (searchParams.has("useAck")) {
592-
if (searchParams.get("useAck") === "true") {
592+
if (searchParams.has("useStatefulReconnect")) {
593+
if (searchParams.get("useStatefulReconnect") === "true") {
593594
this._options._useStatefulReconnect = true;
594595
}
595596
} else if (this._options._useStatefulReconnect === true) {
596-
searchParams.append("useAck", "true");
597+
searchParams.append("useStatefulReconnect", "true");
597598
}
598599

599600
negotiateUrl.search = searchParams.toString();

src/SignalR/clients/ts/signalr/tests/HttpConnection.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ describe("TransportSendQueue", () => {
16661666
_useStatefulReconnect: false,
16671667
WebSocket: TestWebSocket,
16681668
httpClient: new TestHttpClient()
1669-
.on("POST", "http://tempuri.org/negotiate?negotiateVersion=1&useAck=true", () => { throw new Error(); })
1669+
.on("POST", "http://tempuri.org/negotiate?negotiateVersion=1&useStatefulReconnect=true", () => { throw new Error(); })
16701670
.on("POST", "http://tempuri.org/negotiate?negotiateVersion=1", () => negotiateResponse)
16711671
.on("GET", () => ""),
16721672
logger,
@@ -1691,14 +1691,14 @@ describe("TransportSendQueue", () => {
16911691
it("negotiate Stateful Reconnect sets query string", async () => {
16921692
await VerifyLogger.run(async (logger) => {
16931693
const negotiateResponse: INegotiateResponse = { ...defaultNegotiateResponse };
1694-
negotiateResponse.useAck = true;
1694+
negotiateResponse.useStatefulReconnect = true;
16951695

16961696
const options: IHttpConnectionOptions = {
16971697
...commonOptions,
16981698
_useStatefulReconnect: true,
16991699
WebSocket: TestWebSocket,
17001700
httpClient: new TestHttpClient()
1701-
.on("POST", "http://tempuri.org/negotiate?negotiateVersion=1&useAck=true", () => negotiateResponse)
1701+
.on("POST", "http://tempuri.org/negotiate?negotiateVersion=1&useStatefulReconnect=true", () => negotiateResponse)
17021702
.on("GET", () => ""),
17031703
logger,
17041704
} as IHttpConnectionOptions;
@@ -1722,19 +1722,19 @@ describe("TransportSendQueue", () => {
17221722
it("negotiate Stateful Reconnect with query string present", async () => {
17231723
await VerifyLogger.run(async (logger) => {
17241724
const negotiateResponse: INegotiateResponse = { ...defaultNegotiateResponse };
1725-
negotiateResponse.useAck = true;
1725+
negotiateResponse.useStatefulReconnect = true;
17261726

17271727
const options: IHttpConnectionOptions = {
17281728
...commonOptions,
17291729
_useStatefulReconnect: false,
17301730
WebSocket: TestWebSocket,
17311731
httpClient: new TestHttpClient()
1732-
.on("POST", "http://tempuri.org/negotiate?useAck=true&negotiateVersion=1", () => negotiateResponse)
1732+
.on("POST", "http://tempuri.org/negotiate?useStatefulReconnect=true&negotiateVersion=1", () => negotiateResponse)
17331733
.on("GET", () => ""),
17341734
logger,
17351735
} as IHttpConnectionOptions;
17361736

1737-
const connection = new HttpConnection("http://tempuri.org?useAck=true", options);
1737+
const connection = new HttpConnection("http://tempuri.org?useStatefulReconnect=true", options);
17381738

17391739
TestWebSocket.webSocketSet = new PromiseSource();
17401740
const startPromise = connection.start(TransferFormat.Text);
@@ -1754,18 +1754,18 @@ describe("TransportSendQueue", () => {
17541754
await VerifyLogger.run(async (logger) => {
17551755
const negotiateResponse: INegotiateResponse = { ...defaultNegotiateResponse };
17561756
// client didn't request the feature, we should error
1757-
negotiateResponse.useAck = true;
1757+
negotiateResponse.useStatefulReconnect = true;
17581758

17591759
const options: IHttpConnectionOptions = {
17601760
...commonOptions,
17611761
WebSocket: TestWebSocket,
17621762
httpClient: new TestHttpClient()
1763-
.on("POST", "http://tempuri.org/negotiate?useAck=false&negotiateVersion=1", () => negotiateResponse)
1763+
.on("POST", "http://tempuri.org/negotiate?useStatefulReconnect=false&negotiateVersion=1", () => negotiateResponse)
17641764
.on("GET", () => ""),
17651765
logger,
17661766
} as IHttpConnectionOptions;
17671767

1768-
const connection = new HttpConnection("http://tempuri.org?useAck=false", options);
1768+
const connection = new HttpConnection("http://tempuri.org?useStatefulReconnect=false", options);
17691769

17701770
await expect(connection.start(TransferFormat.Text))
17711771
.rejects
@@ -1779,7 +1779,7 @@ describe("TransportSendQueue", () => {
17791779
it("negotiate Stateful Reconnect works with websockets", async () => {
17801780
await VerifyLogger.run(async (logger) => {
17811781
const negotiateResponse: INegotiateResponse = { ...defaultNegotiateResponse };
1782-
negotiateResponse.useAck = true;
1782+
negotiateResponse.useStatefulReconnect = true;
17831783

17841784
const options: IHttpConnectionOptions = {
17851785
...commonOptions,
@@ -1838,7 +1838,7 @@ describe("TransportSendQueue", () => {
18381838
it("negotiate Stateful Reconnect does not work with long polling", async () => {
18391839
await VerifyLogger.run(async (logger) => {
18401840
const negotiateResponse: INegotiateResponse = { ...defaultNegotiateResponse };
1841-
negotiateResponse.useAck = true;
1841+
negotiateResponse.useStatefulReconnect = true;
18421842

18431843
let firstPoll = true;
18441844
const options: IHttpConnectionOptions = {
@@ -1874,7 +1874,7 @@ describe("TransportSendQueue", () => {
18741874
it("using Stateful Reconnect restarts connection", async () => {
18751875
await VerifyLogger.run(async (logger) => {
18761876
const negotiateResponse: INegotiateResponse = { ...defaultNegotiateResponse };
1877-
negotiateResponse.useAck = true;
1877+
negotiateResponse.useStatefulReconnect = true;
18781878

18791879
const options: IHttpConnectionOptions = {
18801880
...commonOptions,
@@ -1937,7 +1937,7 @@ describe("TransportSendQueue", () => {
19371937
it("using Stateful Reconnect restarts connection and closes on error", async () => {
19381938
await VerifyLogger.run(async (logger) => {
19391939
const negotiateResponse: INegotiateResponse = { ...defaultNegotiateResponse };
1940-
negotiateResponse.useAck = true;
1940+
negotiateResponse.useStatefulReconnect = true;
19411941

19421942
const options: IHttpConnectionOptions = {
19431943
...commonOptions,

0 commit comments

Comments
 (0)