Skip to content

Commit 69f71d8

Browse files
mohitpubnubMohit Tejanipubnub-release-bot
authored
Fix: http request cancellation enhancement (#237)
* refactor tests grant calls overlapping * test:fix: authToken for grantToken init() * test:fix:grantToken * test:fix:channelNames correction for message count tests * test:fix:channel Names in subscribe tests * * workflow change to prevent test running on each push. * fix wildcard channel subscribe tests * Update run-tests.yml * update workflow to run tests on any non draft PR * test:fix: subscribe tests grant token access * workflow update for tests on ready PR only. * Reverted changes at run-tests.yml to master * fix: HttpRequest Cancellation through CancellationTokenSource * fix: token added for send file operation callback method * PubNub SDK v7.2.1.0 release. --------- Co-authored-by: Mohit Tejani <[email protected]> Co-authored-by: PubNub Release Bot <[email protected]>
1 parent c953ac5 commit 69f71d8

31 files changed

+785
-1272
lines changed

.pubnub.yml

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
name: c-sharp
2-
version: "7.2.0"
2+
version: "7.2.1"
33
schema: 1
44
scm: github.com/pubnub/c-sharp
55
changelog:
6+
- date: 2025-02-25
7+
version: v7.2.1
8+
changes:
9+
- type: bug
10+
text: "Implemented enhanced cancellation token management for `HttpClient` to allow graceful termination of HTTP requests."
611
- date: 2025-01-29
712
version: v7.2.0
813
changes:
@@ -835,7 +840,7 @@ features:
835840
- QUERY-PARAM
836841
supported-platforms:
837842
-
838-
version: Pubnub 'C#' 7.2.0
843+
version: Pubnub 'C#' 7.2.1
839844
platforms:
840845
- Windows 10 and up
841846
- Windows Server 2008 and up
@@ -846,7 +851,7 @@ supported-platforms:
846851
- .Net Framework 4.6.1+
847852
- .Net Framework 6.0
848853
-
849-
version: PubnubPCL 'C#' 7.2.0
854+
version: PubnubPCL 'C#' 7.2.1
850855
platforms:
851856
- Xamarin.Android
852857
- Xamarin.iOS
@@ -866,7 +871,7 @@ supported-platforms:
866871
- .Net Core
867872
- .Net 6.0
868873
-
869-
version: PubnubUWP 'C#' 7.2.0
874+
version: PubnubUWP 'C#' 7.2.1
870875
platforms:
871876
- Windows Phone 10
872877
- Universal Windows Apps
@@ -890,7 +895,7 @@ sdks:
890895
distribution-type: source
891896
distribution-repository: GitHub
892897
package-name: Pubnub
893-
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.0.0
898+
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.1.0
894899
requires:
895900
-
896901
name: ".Net"
@@ -1173,7 +1178,7 @@ sdks:
11731178
distribution-type: source
11741179
distribution-repository: GitHub
11751180
package-name: PubNubPCL
1176-
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.0.0
1181+
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.1.0
11771182
requires:
11781183
-
11791184
name: ".Net Core"
@@ -1532,7 +1537,7 @@ sdks:
15321537
distribution-type: source
15331538
distribution-repository: GitHub
15341539
package-name: PubnubUWP
1535-
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.0.0
1540+
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.1.0
15361541
requires:
15371542
-
15381543
name: "Universal Windows Platform Development"

CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v7.2.1 - February 25 2025
2+
-----------------------------
3+
- Fixed: implemented enhanced cancellation token management for `HttpClient` to allow graceful termination of HTTP requests.
4+
15
v7.2.0 - January 29 2025
26
-----------------------------
37
- Added: added new optional parameter `IfMatchesEtag` for `setUUIDMetadata` and `setChannelMetadata`. When provided, the server compares the argument value with the eTag on the server and if they don't match a HTTP 412 error is returned.

src/Api/PubnubApi/EndPoint/Files/SendFileOperation.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,13 @@ private void ProcessFileUpload(PNCallback<PNFileUploadResult> callback)
162162
currentCryptoModule = !string.IsNullOrEmpty(currentFileCipherKey) ? new CryptoModule(new LegacyCryptor(currentFileCipherKey, true, pubnubLog), null) : (config.CryptoModule ??= new CryptoModule(new LegacyCryptor(config.CipherKey, true, pubnubLog), null));
163163
}
164164
byte[] postData = GetMultipartFormData(sendFileByteArray, generateFileUploadUrlResult.FileName, generateFileUploadUrlResult.FileUploadRequest.FormFields, dataBoundary, currentCryptoModule, config, pubnubLog);
165+
CancellationTokenSource cts = new CancellationTokenSource();
166+
cts.CancelAfter(TimeSpan.FromMinutes(5));
165167
var transportRequest = new TransportRequest() {
166168
RequestType = Constants.POST,
167169
RequestUrl = generateFileUploadUrlResult.FileUploadRequest.Url,
168170
BodyContentBytes = postData,
171+
CancellationTokenSource = cts
169172
};
170173
transportRequest.Headers.Add("Content-Type", contentType);
171174
PubnubInstance.transportMiddleware.Send(transportRequest: transportRequest).ContinueWith(t => {
@@ -218,7 +221,7 @@ private void ProcessFileUpload(PNCallback<PNFileUploadResult> callback)
218221
requestState.PubnubCallback.OnResponse(default, status);
219222
}
220223
}
221-
});
224+
}, cts.Token);
222225
}
223226

224227
private async Task<PNResult<PNFileUploadResult>> ProcessFileUpload()
@@ -258,11 +261,11 @@ private async Task<PNResult<PNFileUploadResult>> ProcessFileUpload()
258261
RequestType = Constants.POST,
259262
RequestUrl = generateFileUploadUrlResult.FileUploadRequest.Url,
260263
BodyContentBytes = postData,
261-
CancellationToken = cts.Token
264+
CancellationTokenSource = cts
262265
};
263266
transportRequest.Headers.Add("Content-Type", contentType);
264267
Tuple<string, PNStatus> jsonAndStatusTuple;
265-
var transportResponse = await PubnubInstance.transportMiddleware.Send(transportRequest: transportRequest).ConfigureAwait(false);
268+
var transportResponse = await PubnubInstance.transportMiddleware.Send(transportRequest: transportRequest);
266269
if (transportResponse.StatusCode == 204 && transportResponse.Error == null) {
267270
var responseString = "{}";
268271
PNStatus errStatus = GetStatusIfError<PNFileUploadResult>(requestState, responseString);

src/Api/PubnubApi/EndPoint/PubSub/SubscribeManager.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ private void MultiChannelSubscribeRequest<T>(PNOperationType type, string[] chan
290290
};
291291
var subscribeRequestParameter = CreateSubscribeRequestParameter(channels: channels, channelGroups: channelGroups,timetoken: (Convert.ToInt64(timetoken.ToString(), CultureInfo.InvariantCulture) == 0) ? Convert.ToInt64(timetoken.ToString(), CultureInfo.InvariantCulture) : lastTimetoken,region: region,stateJsonValue: channelsJsonState, initialSubscribeUrlParams: initialSubscribeUrlParams, externalQueryParam: externalQueryParam);
292292
var transportRequest = PubnubInstance.transportMiddleware.PreapareTransportRequest(requestParameter: subscribeRequestParameter, operationType: PNOperationType.PNSubscribeOperation);
293-
OngoingSubscriptionCancellationTokenSources[PubnubInstance.InstanceId] = CancellationTokenSource.CreateLinkedTokenSource(transportRequest.CancellationToken);
293+
OngoingSubscriptionCancellationTokenSources[PubnubInstance.InstanceId] =
294+
transportRequest.CancellationTokenSource;
294295
PubnubInstance.transportMiddleware.Send(transportRequest: transportRequest).ContinueWith( t => {
295296
var transportResponse = t.Result;
296297
if (transportResponse.Error == null) {

src/Api/PubnubApi/EndPoint/PubSub/SubscribeManager2.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public async Task<Tuple<HandshakeResponse, PNStatus>> HandshakeRequest(PNOperati
3333
if (config.MaintainPresenceState) presenceState = BuildJsonUserState(channels, channelGroups, true);
3434
var requestParameter = CreateSubscribeRequestParameter(channels: channels, channelGroups: channelGroups, timetoken: timetoken.GetValueOrDefault(), region: region.GetValueOrDefault(), stateJsonValue: presenceState, initialSubscribeUrlParams: initialSubscribeUrlParams, externalQueryParam: externalQueryParam);
3535
var transportRequest = pubnubInstance.transportMiddleware.PreapareTransportRequest(requestParameter: requestParameter, operationType: PNOperationType.PNSubscribeOperation);
36-
cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(transportRequest.CancellationToken);
36+
cancellationTokenSource = transportRequest.CancellationTokenSource;
3737
RequestState<HandshakeResponse> pubnubRequestState = new RequestState<HandshakeResponse>
3838
{
3939
Channels = channels,
@@ -85,7 +85,7 @@ internal async Task<Tuple<ReceivingResponse<object>, PNStatus>> ReceiveRequest<T
8585
string channelsJsonState = BuildJsonUserState(channels, channelGroups, false);
8686
var requestParameter = CreateSubscribeRequestParameter(channels: channels, channelGroups: channelGroups, timetoken: timetoken.GetValueOrDefault(), region: region.GetValueOrDefault(), stateJsonValue: channelsJsonState, initialSubscribeUrlParams: initialSubscribeUrlParams, externalQueryParam: externalQueryParam);
8787
var transportRequest = pubnubInstance.transportMiddleware.PreapareTransportRequest(requestParameter: requestParameter, operationType: PNOperationType.PNSubscribeOperation);
88-
cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(transportRequest.CancellationToken);
88+
cancellationTokenSource = transportRequest.CancellationTokenSource;
8989
RequestState<ReceivingResponse<object>> pubnubRequestState = new RequestState<ReceivingResponse<object>>
9090
{
9191
Channels = channels,

src/Api/PubnubApi/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
[assembly: AssemblyProduct("Pubnub C# SDK")]
1212
[assembly: AssemblyCopyright("Copyright © 2021")]
1313
[assembly: AssemblyTrademark("")]
14-
[assembly: AssemblyVersion("7.2.0.0")]
15-
[assembly: AssemblyFileVersion("7.2.0.0")]
14+
[assembly: AssemblyVersion("7.2.1.0")]
15+
[assembly: AssemblyFileVersion("7.2.1.0")]
1616
// Setting ComVisible to false makes the types in this assembly not visible
1717
// to COM components. If you need to access a type in this assembly from
1818
// COM, set the ComVisible attribute to true on that type.

src/Api/PubnubApi/PubnubApi.csproj

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414

1515
<PropertyGroup>
1616
<PackageId>Pubnub</PackageId>
17-
<PackageVersion>7.2.0.0</PackageVersion>
17+
<PackageVersion>7.2.1.0</PackageVersion>
1818
<Title>PubNub C# .NET - Web Data Push API</Title>
1919
<Authors>Pandu Masabathula</Authors>
2020
<Owners>PubNub</Owners>
2121
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2222
<PackageIconUrl>http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png</PackageIconUrl>
2323
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
2424
<RepositoryUrl>https://github.com/pubnub/c-sharp/</RepositoryUrl>
25-
<PackageReleaseNotes>Added new optional parameter `IfMatchesEtag` for `setUUIDMetadata` and `setChannelMetadata`. When provided, the server compares the argument value with the eTag on the server and if they don't match a HTTP 412 error is returned.
26-
Fixes issue of not getting `PNSubscriptionChangedCategory` status when subscription change happens.</PackageReleaseNotes>
25+
<PackageReleaseNotes>Implemented enhanced cancellation token management for `HttpClient` to allow graceful termination of HTTP requests.</PackageReleaseNotes>
2726
<PackageTags>Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing</PackageTags>
2827
<!--<Summary>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Summary>-->
2928
<Description>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Description>

0 commit comments

Comments
 (0)