Skip to content

Commit

Permalink
Fix: http request cancellation enhancement (#237)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Feb 25, 2025
1 parent c953ac5 commit 69f71d8
Show file tree
Hide file tree
Showing 31 changed files with 785 additions and 1,272 deletions.
19 changes: 12 additions & 7 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: c-sharp
version: "7.2.0"
version: "7.2.1"
schema: 1
scm: github.com/pubnub/c-sharp
changelog:
- date: 2025-02-25
version: v7.2.1
changes:
- type: bug
text: "Implemented enhanced cancellation token management for `HttpClient` to allow graceful termination of HTTP requests."
- date: 2025-01-29
version: v7.2.0
changes:
Expand Down Expand Up @@ -835,7 +840,7 @@ features:
- QUERY-PARAM
supported-platforms:
-
version: Pubnub 'C#' 7.2.0
version: Pubnub 'C#' 7.2.1
platforms:
- Windows 10 and up
- Windows Server 2008 and up
Expand All @@ -846,7 +851,7 @@ supported-platforms:
- .Net Framework 4.6.1+
- .Net Framework 6.0
-
version: PubnubPCL 'C#' 7.2.0
version: PubnubPCL 'C#' 7.2.1
platforms:
- Xamarin.Android
- Xamarin.iOS
Expand All @@ -866,7 +871,7 @@ supported-platforms:
- .Net Core
- .Net 6.0
-
version: PubnubUWP 'C#' 7.2.0
version: PubnubUWP 'C#' 7.2.1
platforms:
- Windows Phone 10
- Universal Windows Apps
Expand All @@ -890,7 +895,7 @@ sdks:
distribution-type: source
distribution-repository: GitHub
package-name: Pubnub
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.0.0
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.1.0
requires:
-
name: ".Net"
Expand Down Expand Up @@ -1173,7 +1178,7 @@ sdks:
distribution-type: source
distribution-repository: GitHub
package-name: PubNubPCL
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.0.0
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.1.0
requires:
-
name: ".Net Core"
Expand Down Expand Up @@ -1532,7 +1537,7 @@ sdks:
distribution-type: source
distribution-repository: GitHub
package-name: PubnubUWP
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.0.0
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.1.0
requires:
-
name: "Universal Windows Platform Development"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v7.2.1 - February 25 2025
-----------------------------
- Fixed: implemented enhanced cancellation token management for `HttpClient` to allow graceful termination of HTTP requests.

v7.2.0 - January 29 2025
-----------------------------
- 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.
Expand Down
9 changes: 6 additions & 3 deletions src/Api/PubnubApi/EndPoint/Files/SendFileOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,13 @@ private void ProcessFileUpload(PNCallback<PNFileUploadResult> callback)
currentCryptoModule = !string.IsNullOrEmpty(currentFileCipherKey) ? new CryptoModule(new LegacyCryptor(currentFileCipherKey, true, pubnubLog), null) : (config.CryptoModule ??= new CryptoModule(new LegacyCryptor(config.CipherKey, true, pubnubLog), null));
}
byte[] postData = GetMultipartFormData(sendFileByteArray, generateFileUploadUrlResult.FileName, generateFileUploadUrlResult.FileUploadRequest.FormFields, dataBoundary, currentCryptoModule, config, pubnubLog);
CancellationTokenSource cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromMinutes(5));
var transportRequest = new TransportRequest() {
RequestType = Constants.POST,
RequestUrl = generateFileUploadUrlResult.FileUploadRequest.Url,
BodyContentBytes = postData,
CancellationTokenSource = cts
};
transportRequest.Headers.Add("Content-Type", contentType);
PubnubInstance.transportMiddleware.Send(transportRequest: transportRequest).ContinueWith(t => {
Expand Down Expand Up @@ -218,7 +221,7 @@ private void ProcessFileUpload(PNCallback<PNFileUploadResult> callback)
requestState.PubnubCallback.OnResponse(default, status);
}
}
});
}, cts.Token);
}

private async Task<PNResult<PNFileUploadResult>> ProcessFileUpload()
Expand Down Expand Up @@ -258,11 +261,11 @@ private async Task<PNResult<PNFileUploadResult>> ProcessFileUpload()
RequestType = Constants.POST,
RequestUrl = generateFileUploadUrlResult.FileUploadRequest.Url,
BodyContentBytes = postData,
CancellationToken = cts.Token
CancellationTokenSource = cts
};
transportRequest.Headers.Add("Content-Type", contentType);
Tuple<string, PNStatus> jsonAndStatusTuple;
var transportResponse = await PubnubInstance.transportMiddleware.Send(transportRequest: transportRequest).ConfigureAwait(false);
var transportResponse = await PubnubInstance.transportMiddleware.Send(transportRequest: transportRequest);
if (transportResponse.StatusCode == 204 && transportResponse.Error == null) {
var responseString = "{}";
PNStatus errStatus = GetStatusIfError<PNFileUploadResult>(requestState, responseString);
Expand Down
3 changes: 2 additions & 1 deletion src/Api/PubnubApi/EndPoint/PubSub/SubscribeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ private void MultiChannelSubscribeRequest<T>(PNOperationType type, string[] chan
};
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);
var transportRequest = PubnubInstance.transportMiddleware.PreapareTransportRequest(requestParameter: subscribeRequestParameter, operationType: PNOperationType.PNSubscribeOperation);
OngoingSubscriptionCancellationTokenSources[PubnubInstance.InstanceId] = CancellationTokenSource.CreateLinkedTokenSource(transportRequest.CancellationToken);
OngoingSubscriptionCancellationTokenSources[PubnubInstance.InstanceId] =
transportRequest.CancellationTokenSource;
PubnubInstance.transportMiddleware.Send(transportRequest: transportRequest).ContinueWith( t => {
var transportResponse = t.Result;
if (transportResponse.Error == null) {
Expand Down
4 changes: 2 additions & 2 deletions src/Api/PubnubApi/EndPoint/PubSub/SubscribeManager2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<Tuple<HandshakeResponse, PNStatus>> HandshakeRequest(PNOperati
if (config.MaintainPresenceState) presenceState = BuildJsonUserState(channels, channelGroups, true);
var requestParameter = CreateSubscribeRequestParameter(channels: channels, channelGroups: channelGroups, timetoken: timetoken.GetValueOrDefault(), region: region.GetValueOrDefault(), stateJsonValue: presenceState, initialSubscribeUrlParams: initialSubscribeUrlParams, externalQueryParam: externalQueryParam);
var transportRequest = pubnubInstance.transportMiddleware.PreapareTransportRequest(requestParameter: requestParameter, operationType: PNOperationType.PNSubscribeOperation);
cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(transportRequest.CancellationToken);
cancellationTokenSource = transportRequest.CancellationTokenSource;
RequestState<HandshakeResponse> pubnubRequestState = new RequestState<HandshakeResponse>
{
Channels = channels,
Expand Down Expand Up @@ -85,7 +85,7 @@ internal async Task<Tuple<ReceivingResponse<object>, PNStatus>> ReceiveRequest<T
string channelsJsonState = BuildJsonUserState(channels, channelGroups, false);
var requestParameter = CreateSubscribeRequestParameter(channels: channels, channelGroups: channelGroups, timetoken: timetoken.GetValueOrDefault(), region: region.GetValueOrDefault(), stateJsonValue: channelsJsonState, initialSubscribeUrlParams: initialSubscribeUrlParams, externalQueryParam: externalQueryParam);
var transportRequest = pubnubInstance.transportMiddleware.PreapareTransportRequest(requestParameter: requestParameter, operationType: PNOperationType.PNSubscribeOperation);
cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(transportRequest.CancellationToken);
cancellationTokenSource = transportRequest.CancellationTokenSource;
RequestState<ReceivingResponse<object>> pubnubRequestState = new RequestState<ReceivingResponse<object>>
{
Channels = channels,
Expand Down
4 changes: 2 additions & 2 deletions src/Api/PubnubApi/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
[assembly: AssemblyProduct("Pubnub C# SDK")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("7.2.0.0")]
[assembly: AssemblyFileVersion("7.2.0.0")]
[assembly: AssemblyVersion("7.2.1.0")]
[assembly: AssemblyFileVersion("7.2.1.0")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
Expand Down
5 changes: 2 additions & 3 deletions src/Api/PubnubApi/PubnubApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@

<PropertyGroup>
<PackageId>Pubnub</PackageId>
<PackageVersion>7.2.0.0</PackageVersion>
<PackageVersion>7.2.1.0</PackageVersion>
<Title>PubNub C# .NET - Web Data Push API</Title>
<Authors>Pandu Masabathula</Authors>
<Owners>PubNub</Owners>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageIconUrl>http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png</PackageIconUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/pubnub/c-sharp/</RepositoryUrl>
<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.
Fixes issue of not getting `PNSubscriptionChangedCategory` status when subscription change happens.</PackageReleaseNotes>
<PackageReleaseNotes>Implemented enhanced cancellation token management for `HttpClient` to allow graceful termination of HTTP requests.</PackageReleaseNotes>
<PackageTags>Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing</PackageTags>
<!--<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>-->
<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>
Expand Down
Loading

0 comments on commit 69f71d8

Please sign in to comment.