Skip to content

Commit f3bfc68

Browse files
mohitpubnubMohit Tejanijakub-grzesiowskipubnub-release-bot
authored
reafctor: remove excess logging in transport module. (#246)
* reafctor: remove excess logging in transport module. Added thread info for transport. Minor adjustment in event parsing. * fix: UWP compatibility Task instead Thread for printing thread id * Add missing .ConfigureAwait(false) * PubNub SDK v7.3.6.0 release. --------- Co-authored-by: Mohit Tejani <[email protected]> Co-authored-by: PUBNUB\jakub.grzesiowski <[email protected]> Co-authored-by: PubNub Release Bot <[email protected]>
1 parent 3a904f5 commit f3bfc68

File tree

16 files changed

+96
-67
lines changed

16 files changed

+96
-67
lines changed

.pubnub.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
name: c-sharp
2-
version: "7.3.5"
2+
version: "7.3.6"
33
schema: 1
44
scm: github.com/pubnub/c-sharp
55
changelog:
6+
- date: 2025-04-03
7+
version: v7.3.6
8+
changes:
9+
- type: bug
10+
text: "Reafctor: Removed excess logging from transport module. Removed redundant logging from transport layer and added thread id information for tracking http request."
611
- date: 2025-03-31
712
version: v7.3.5
813
changes:
@@ -872,7 +877,7 @@ features:
872877
- QUERY-PARAM
873878
supported-platforms:
874879
-
875-
version: Pubnub 'C#' 7.3.5
880+
version: Pubnub 'C#' 7.3.6
876881
platforms:
877882
- Windows 10 and up
878883
- Windows Server 2008 and up
@@ -883,7 +888,7 @@ supported-platforms:
883888
- .Net Framework 4.6.1+
884889
- .Net Framework 6.0
885890
-
886-
version: PubnubPCL 'C#' 7.3.5
891+
version: PubnubPCL 'C#' 7.3.6
887892
platforms:
888893
- Xamarin.Android
889894
- Xamarin.iOS
@@ -903,7 +908,7 @@ supported-platforms:
903908
- .Net Core
904909
- .Net 6.0
905910
-
906-
version: PubnubUWP 'C#' 7.3.5
911+
version: PubnubUWP 'C#' 7.3.6
907912
platforms:
908913
- Windows Phone 10
909914
- Universal Windows Apps
@@ -927,7 +932,7 @@ sdks:
927932
distribution-type: source
928933
distribution-repository: GitHub
929934
package-name: Pubnub
930-
location: https://github.com/pubnub/c-sharp/releases/tag/v7.3.5.0
935+
location: https://github.com/pubnub/c-sharp/releases/tag/v7.3.6.0
931936
requires:
932937
-
933938
name: ".Net"
@@ -1210,7 +1215,7 @@ sdks:
12101215
distribution-type: source
12111216
distribution-repository: GitHub
12121217
package-name: PubNubPCL
1213-
location: https://github.com/pubnub/c-sharp/releases/tag/v7.3.5.0
1218+
location: https://github.com/pubnub/c-sharp/releases/tag/v7.3.6.0
12141219
requires:
12151220
-
12161221
name: ".Net Core"
@@ -1569,7 +1574,7 @@ sdks:
15691574
distribution-type: source
15701575
distribution-repository: GitHub
15711576
package-name: PubnubUWP
1572-
location: https://github.com/pubnub/c-sharp/releases/tag/v7.3.5.0
1577+
location: https://github.com/pubnub/c-sharp/releases/tag/v7.3.6.0
15731578
requires:
15741579
-
15751580
name: "Universal Windows Platform Development"

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v7.3.6 - April 03 2025
2+
-----------------------------
3+
- Fixed: reafctor: Removed excess logging from transport module. Removed redundant logging from transport layer and added thread id information for tracking http request.
4+
15
v7.3.5 - March 31 2025
26
-----------------------------
37
- Fixed: standardize connection configuration to address inconsistent platform defaults leading to socket exhaustion under high load.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ private async Task<PNResult<PNFileUploadResult>> ProcessFileUpload()
333333
};
334334
transportRequest.Headers.Add("Content-Type", contentType);
335335
Tuple<string, PNStatus> jsonAndStatusTuple;
336-
var transportResponse = await PubnubInstance.transportMiddleware.Send(transportRequest: transportRequest);
336+
var transportResponse = await PubnubInstance.transportMiddleware.Send(transportRequest: transportRequest).ConfigureAwait(false);
337337
if (transportResponse.StatusCode == 204 && transportResponse.Error == null)
338338
{
339339
var responseString = "{}";

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ public SubscribeManager(PNConfiguration pubnubConfig, IJsonPluggableLibrary json
3535
internal void MultiChannelUnSubscribeAll<T>(PNOperationType type, Dictionary<string, object> externalQueryParam)
3636
{
3737
//Retrieve the current channels already subscribed previously and terminate them
38-
TerminateCurrentSubscriberRequest();
38+
if (OngoingSubscriptionCancellationTokenSources.TryGetValue(PubnubInstance.InstanceId, out var tokenSource))
39+
{
40+
if (tokenSource != null)
41+
{
42+
IsCurrentSubscriptionCancellationRequested[PubnubInstance.InstanceId] = true;
43+
TerminateCurrentSubscriberRequest();
44+
}
45+
}
3946
string[] currentChannels = SubscriptionChannels.ContainsKey(PubnubInstance.InstanceId)
4047
? SubscriptionChannels[PubnubInstance.InstanceId].Keys?.ToArray() ?? []
4148
: [];
@@ -53,13 +60,18 @@ internal void MultiChannelUnSubscribeAll<T>(PNOperationType type, Dictionary<str
5360
operationType: PNOperationType.Leave);
5461
PubnubInstance.transportMiddleware.Send(transportRequest: leaveTransportRequest).ContinueWith(t =>
5562
{
56-
SubscriptionChannels[PubnubInstance.InstanceId]?.Clear();
57-
SubscriptionChannelGroups[PubnubInstance.InstanceId]?.Clear();
63+
try
64+
{
65+
SubscriptionChannels[PubnubInstance.InstanceId]?.Clear();
66+
SubscriptionChannelGroups[PubnubInstance.InstanceId]?.Clear();
67+
}
68+
catch (Exception e)
69+
{
70+
logger?.Debug($"No subscription found.{e.Message}");
71+
}
5872
});
5973
}
60-
61-
SubscriptionChannels[PubnubInstance.InstanceId]?.Clear();
62-
SubscriptionChannelGroups[PubnubInstance.InstanceId]?.Clear();
74+
6375
TerminateCurrentSubscriberRequest();
6476
TerminateReconnectTimer();
6577
TerminatePresenceHeartbeatTimer();
@@ -294,15 +306,15 @@ internal void MultiChannelUnSubscribeInit<T>(PNOperationType type, string channe
294306
catch (Exception ex)
295307
{
296308
logger?.Error(
297-
$"At SubscribeManager.MultiChannelUnSubscribeInit() \n channel(s)={string.Join(",", validChannels.OrderBy(x => x).ToArray())} \n cg(s)={string.Join(",", validChannelGroups.OrderBy(x => x).ToArray())} \n Exception Details={ex}");
309+
$"SubscribeManager.MultiChannelUnSubscribeInit() \n channel(s)={string.Join(",", validChannels.OrderBy(x => x).ToArray())} \n cg(s)={string.Join(",", validChannelGroups.OrderBy(x => x).ToArray())} \n Exception Details={ex}");
298310
}
299311
}
300312

301313
internal void MultiChannelSubscribeInit<T>(PNOperationType responseType, string[] rawChannels,
302314
string[] rawChannelGroups, Dictionary<string, string> initialSubscribeUrlParams,
303315
Dictionary<string, object> externalQueryParam)
304316
{
305-
logger?.Debug("INITIAL SUBSCRIBE REQUEST getting executed through MultiChannelSubscribeInit");
317+
logger?.Trace("SubscribeManager: MultiChannelSubscribeInit() Invoked");
306318
try
307319
{
308320
bool channelGroupSubscribeOnly = false;
@@ -355,8 +367,7 @@ internal void MultiChannelSubscribeInit<T>(PNOperationType responseType, string[
355367
{
356368
channelGroupSubscribeOnly = true;
357369
}
358-
359-
logger?.Debug($"MultiChannelSubscribeRequest with tt=0");
370+
360371
MultiChannelSubscribeRequest<T>(responseType, channels, channelGroups, 0, 0, false,
361372
initialSubscribeUrlParams, externalQueryParam);
362373
if (SubscribeHeartbeatCheckTimer != null)
@@ -451,8 +462,7 @@ private void MultiChannelSubscribeRequest<T>(PNOperationType type, string[] chan
451462
long lastTimetoken = LastSubscribeTimetoken.ContainsKey(PubnubInstance.InstanceId)
452463
? LastSubscribeTimetoken[PubnubInstance.InstanceId]
453464
: 0;
454-
logger?.Trace(
455-
$"Building request for channel(s)={multiChannel}, channelgroup(s)={multiChannelGroup} with timetoken={lastTimetoken}");
465+
logger?.Trace($"Building request for channel(s)={multiChannel}, channelgroup(s)={multiChannelGroup} with timetoken={lastTimetoken}");
456466
string channelsJsonState = BuildJsonUserState(channels, channelGroups, false);
457467
config[PubnubInstance.InstanceId].UserId =
458468
CurrentUserId[PubnubInstance.InstanceId]; // to make sure we capture if UUID is changed
@@ -486,6 +496,7 @@ private void MultiChannelSubscribeRequest<T>(PNOperationType type, string[] chan
486496
{
487497
networkConnection = true;
488498
var json = Encoding.UTF8.GetString(transportResponse.Content);
499+
logger?.Debug($"SubscribeManager received response: {json}");
489500
pubnubRequestState.GotJsonResponse = true;
490501
if (!string.IsNullOrEmpty(json))
491502
{

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public async Task<Tuple<HandshakeResponse, PNStatus>> HandshakeRequest(PNOperati
4747

4848
if (transportResponse.StatusCode == Constants.HttpRequestSuccessStatusCode && transportResponse.Error == null && transportResponse.Content != null) {
4949
var responseJson = Encoding.UTF8.GetString(transportResponse.Content);
50+
logger?.Debug($"Handshake Effect received json: {responseJson}");
5051
PNStatus status = new PNStatus(null, PNOperationType.PNSubscribeOperation, PNStatusCategory.PNConnectedCategory, channels, channelGroups);
5152
HandshakeResponse handshakeResponse = jsonLibrary.DeserializeToObject<HandshakeResponse>(responseJson);
5253
return new Tuple<HandshakeResponse, PNStatus>(handshakeResponse, status);
@@ -72,13 +73,13 @@ internal void HandshakeRequestCancellation()
7273
cancellationTokenSource.Dispose();
7374
} else
7475
{
75-
logger?.Trace($" SubscribeManager HandshakeRequestCancellation. No request to cancel.");
76+
logger?.Trace($" SubscribeManager HandshakeRequestCancellation. No request to cancel.");
7677
}
7778

78-
logger?.Trace($"SubscribeManager HandshakeRequestCancellation. Done.");
79+
logger?.Trace($"SubscribeManager HandshakeRequestCancellation. Done.");
7980
} catch (Exception ex)
8081
{
81-
logger?.Trace($" SubscribeManager HandshakeRequestCancellation Exception: {ex}");
82+
logger?.Trace($" SubscribeManager HandshakeRequestCancellation Exception: {ex}");
8283
}
8384
}
8485
internal async Task<Tuple<ReceivingResponse<object>, PNStatus>> ReceiveRequest<T>(PNOperationType responseType, string[] channels, string[] channelGroups, long? timetoken, int? region, Dictionary<string, string> initialSubscribeUrlParams, Dictionary<string, object> externalQueryParam)
@@ -102,6 +103,7 @@ internal async Task<Tuple<ReceivingResponse<object>, PNStatus>> ReceiveRequest<T
102103
var transportResponse = await pubnubInstance.transportMiddleware.Send(transportRequest: transportRequest);
103104
if (transportResponse.Content != null && transportResponse.Error == null && transportResponse.StatusCode == Constants.HttpRequestSuccessStatusCode) {
104105
var responseJson = Encoding.UTF8.GetString(transportResponse.Content);
106+
logger?.Debug($"Receiving Effect received json: {responseJson}");
105107
PNStatus status = new PNStatus(null, PNOperationType.PNSubscribeOperation, PNStatusCategory.PNConnectedCategory, channels, channelGroups);
106108
ReceivingResponse<object> receiveResponse = jsonLibrary.DeserializeToObject<ReceivingResponse<object>>(responseJson);
107109
return new Tuple<ReceivingResponse<object>, PNStatus>(receiveResponse, status);
@@ -119,7 +121,7 @@ internal async Task<Tuple<ReceivingResponse<object>, PNStatus>> ReceiveRequest<T
119121
} catch (Exception ex)
120122
{
121123
logger?.Error(
122-
$" SubscribeManager=> MultiChannelSubscribeInit \n channel(s)={string.Join(",", channels.OrderBy(x => x).ToArray())} \n cg(s)={string.Join(",", channelGroups.OrderBy(x => x).ToArray())} \n Exception Details={ex}");
124+
$" Receiving effect exception for \n channel(s)={string.Join(",", channels.OrderBy(x => x).ToArray())} \n cg(s)={string.Join(",", channelGroups.OrderBy(x => x).ToArray())} \n Exception Details={ex}");
123125
}
124126
return resp;
125127
}
@@ -131,12 +133,12 @@ internal void ReceiveRequestCancellation()
131133
cancellationTokenSource.Cancel();
132134
cancellationTokenSource.Dispose();
133135
} else {
134-
logger?.Trace($"SubscribeManager RequestCancellation. No request to cancel.");
136+
logger?.Trace($"SubscribeManager RequestCancellation. No request to cancel.");
135137
}
136-
logger?.Trace($"SubscribeManager ReceiveRequestCancellation. Done.");
138+
logger?.Trace($"SubscribeManager ReceiveRequestCancellation. Done.");
137139
} catch (Exception ex)
138140
{
139-
logger?.Trace($"SubscribeManager ReceiveRequestCancellation Exception: {ex}");
141+
logger?.Trace($"SubscribeManager ReceiveRequestCancellation Exception: {ex}");
140142
}
141143
}
142144

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public IUnsubscribeOperation<T> QueryParam(Dictionary<string, object> customQuer
4545

4646
public void Execute()
4747
{
48-
logger?.Trace($"{GetType().Name} Execute invoked");
49-
logger?.Debug($"PUBNUB Unsubscribe request Execute() received channels = {string.Join(", ", subscribeChannelNames)}");
48+
logger?.Trace($"{GetType().Name} Execute invoked with channels = {string.Join(", ", subscribeChannelNames)}");
5049
Unsubscribe(subscribeChannelNames, subscribeChannelGroupNames);
5150
}
5251

@@ -60,7 +59,7 @@ private void Unsubscribe(string[] channels, string[] channelGroups)
6059
string channel = (channels != null) ? string.Join(",", channels.OrderBy(x => x).ToArray()) : "";
6160
string channelGroup = (channelGroups != null) ? string.Join(",", channelGroups.OrderBy(x => x).ToArray()) : "";
6261

63-
logger?.Debug($"requested unsubscribe for channel(s)={channel}, cg(s)={channelGroup}");
62+
logger?.Debug($"{GetType().Name} requested unsubscribe for channel(s)={channel}, cg(s)={channelGroup}");
6463

6564
SubscribeManager manager = new SubscribeManager(config, jsonLibrary, unit, pubnubTokenManager, PubnubInstance);
6665
manager.CurrentPubnubInstance(PubnubInstance);

src/Api/PubnubApi/EndPoint/StoragePlayback/MessageCountsOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public async Task<PNResult<PNMessageCountResult>> ExecuteAsync()
7373
throw new MissingMemberException("Invalid Subscribe Key");
7474
}
7575

76-
return await MessageCounts(this.channelNames, this.timetokens, this.queryParam);
76+
return await MessageCounts(this.channelNames, this.timetokens, this.queryParam).ConfigureAwait(false);
7777
}
7878

7979
internal void Retry()

src/Api/PubnubApi/EventEngine/Core/Engine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private async void OnEvent(EventQueue q)
5050
transitioning = true;
5151
while (q.Count > 0)
5252
{
53-
await Transition(q.Dequeue());
53+
await Transition(q.Dequeue()).ConfigureAwait(false);
5454
}
5555

5656
transitioning = false;

src/Api/PubnubApi/EventEngine/Core/EventQueue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async Task Loop<T>(System.Func<IEvent, Task<T>> function)
4545
{
4646
while (Count > 0)
4747
{
48-
await function(Dequeue());
48+
await function(Dequeue()).ConfigureAwait(false);
4949
}
5050
}
5151

src/Api/PubnubApi/JsonDataParse/EventDeserializer.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ private PNPresenceEventResult DeserializePresenceEvent(IDictionary<string, objec
5959
presenceEvent.Timestamp = presenceTimeStamp;
6060
}
6161

62-
presenceEvent.Uuid = presenceDataFields["uuid"]?.ToString();
62+
if (presenceDataFields.TryGetValue("uuid", out var uuidValue))
63+
{
64+
presenceEvent.Uuid = uuidValue?.ToString();
65+
}
6366

6467
if (Int32.TryParse(presenceDataFields["occupancy"]?.ToString(), out var presenceOccupany))
6568
{
@@ -79,16 +82,20 @@ private PNPresenceEventResult DeserializePresenceEvent(IDictionary<string, objec
7982
presenceEvent.Timetoken = presenceTimetoken;
8083
}
8184

82-
presenceEvent.Channel = jsonFields["channel"]?.ToString();
83-
presenceEvent.Channel = presenceEvent.Channel?.Replace("-pnpres", "");
85+
if (jsonFields.TryGetValue("channel", out var channelValue))
86+
{
87+
presenceEvent.Channel = channelValue?.ToString()?.Replace("-pnpres", "");
88+
}
8489

85-
presenceEvent.Subscription = jsonFields["channelGroup"]?.ToString();
86-
presenceEvent.Subscription = presenceEvent.Subscription?.Replace("-pnpres", "");
90+
if (jsonFields.TryGetValue("channelGroup", out var subscriptionValue))
91+
{
92+
presenceEvent.Subscription = subscriptionValue?.ToString()?.Replace("-pnpres", "");
93+
}
8794

8895

89-
if (jsonFields["userMetadata"] != null)
96+
if (jsonFields.TryGetValue("userMetadata", out object userMetadataValue))
9097
{
91-
presenceEvent.UserMetadata = jsonFields["userMetadata"];
98+
presenceEvent.UserMetadata = userMetadataValue;
9299
}
93100

94101
if (presenceEvent.Event != null && presenceEvent.Event.ToLowerInvariant() == "interval")

0 commit comments

Comments
 (0)