Giter VIP home page Giter VIP logo

c-sharp's People

Contributors

budgetpreneur avatar client-engineering-bot avatar crimsonred avatar davidnub avatar jakub-grzesiowski avatar marceloinacio avatar maxpresman avatar messagingmoore avatar mikedobrzan avatar mohitpubnub avatar musashiwasajedi avatar parfeon avatar seba-aln avatar stephenlb avatar techwritermat avatar xavrax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

c-sharp's Issues

Do a proper lib in the NuGet package

Hi,
instead of a PubNub.cs file and a reference of Newtonsoft.Json could you provide a proper NuGet package where PubNub.cs is in a lib, and Newtonsoft.Json is referenced from his own nuget package. The current packaging make little sense.

Thanks.

CleanupTelemetryData Taking Too Much CPU/Memory

Code Optimizations in Azure has identified a excessive Memory usage by the "PubnubApi.EndPoint.TelemetryManager.CleanupTelemetryData" method. It has 3 recommendations.

Recommendation 1:

Description: A lot of CPU or Memory is being spent in Enumerable.ToDictionary().

Current Condition: 19% of your Memory was spent in Enumerable.ToDictionary called from PubnubApi.EndPoint.TelemetryManager.CleanupTelemetryData. We expected this value to be <2%.

Recommendations: Verify that Enumerable.ToDictionary() isn't being called for a few look-ups in the resulting Dictionary<K, V>. This can instead be accomplished simply by enumerating over the Enumerable.

Recommendation 2:

**Description: ** Task.ScheduleAndStart is causing unusually high memory allocations.

Current Condition: 6% of your Memory was spent in Task.ScheduleAndStart called from PubnubApi.EndPoint.TelemetryManager.CleanupTelemetryData. We expected this value to be <1%.

Recommendations: Consider investigating why Task.ScheduleAndStart is causing higher than expected memory allocations.

Recommendation 3:

**Description: ** Excessive string concatenation is causing lots of allocations and CPU consumption.

Current Condition: 3% of your Memory was spent in String.Concat called from PubnubApi.EndPoint.TelemetryManager.CleanupTelemetryData. We expected this value to be <1%.

Recommendations: Consider using cheaper alternatives such as String.Join or a StringBuilder instead.

Nuget 6.19.4 having issue with issue with **DECRYPT ERROR** on FetchHistory

Just upgraded the Pubnub from 3.18.4 to direct 6.19.4.

All went well but Fetch history having exeption on decryption.

Same thing worked for nuget 6.19.3.

After checking last commits for 6.19.4 I see exception at this place.

File: src/Api/PubnubApi/Security/SecureMessage.cs
Line number: 159

object decodeMessage = jsonLib.DeserializeToObject((decryptMessage == "**DECRYPT ERROR**") ? decryptMessage : decryptMessage);

if there is DECRYPT ERROR, it should not be taking decryptMessage, it should be taking kvpValue.Value.ToString() as its done at other places.

Possible memory leak when used with ASP.NET Core DI

While investigating an issue with high CPU usage, a memory dump was taken of a long-running ASP.NET Core 6 server application (see below) that uses the PubNubPCL library.

The heap has a lot of retained instances of objects related to the PubNub API, particularly PNConfguration which, after about 3 days of continuous operation, occupies 107MB of heap space.

I suspect the issue lies with the lifetime of the PubNub client in the DI container. We have a thin wrapper around the PubNub API that we inject with a Transient lifetime. The constructor creates a new PubNub object and configures it every time it is injected.

Based on the large number of PubnubApi.ConcurrentDictionary objects also on the heap, I believe the PubNub client is supposed to have a Singleton lifetime, but I could not find any guidance in the documentation regarding DI containers.

Can you confirm the expected lifetime of the PubNub client? Is it expected to be a Singleton, or can it be constructed as needed in a long-running service?

Here is the relevant part of the heap analysis created with dotnet-dump. The command used was dumpheap -stat -live (statistical analysis of live objects only).

              MT    Count    TotalSize Class Name
[snip]
00007f832b80f308   235225      7527200 PubnubApi.ConcurrentDictionary`2[[System.String, System.Private.CoreLib],[System.Net.HttpWebRequest, System.Net.Requests]]
00007f83294d3a10   235225      7527200 PubnubApi.NewtonsoftJsonDotNet
00007f832b827460        1      7786800 System.Collections.Generic.Dictionary`2+Entry[[System.String, System.Private.CoreLib],[PubnubApi.ConcurrentDictionary`2[[System.String, System.Private.CoreLib],[System.Net.HttpWebRequest, System.Net.Requests]], PubnubPCL]][]
00007f832b826520        1      7786800 System.Collections.Generic.Dictionary`2+Entry[[System.String, System.Private.CoreLib],[PubnubApi.EndPoint.TokenManager, PubnubPCL]][]
00007f832b8262a0        1      7786800 System.Collections.Generic.Dictionary`2+Entry[[System.String, System.Private.CoreLib],[PubnubApi.IPubnubLog, PubnubPCL]][]
00007f832b826020        1      7786800 System.Collections.Generic.Dictionary`2+Entry[[System.String, System.Private.CoreLib],[PubnubApi.PNConfiguration, PubnubPCL]][]
00007f83294d45b8   235225     13172600 PubnubApi.EndPoint.TokenManager
00007f8325678080     4495     13808408 System.Int32[]
00007f832b80b6a0   470451     15054432 PubnubApi.ConcurrentDictionary`2[[System.String, System.Private.CoreLib],[System.Boolean, System.Private.CoreLib]]
00007f832b8276e0        2     15573600 System.Collections.Generic.Dictionary`2+Entry[[System.String, System.Private.CoreLib],[PubnubApi.ConcurrentDictionary`2[[System.String, System.Private.CoreLib],[System.Boolean, System.Private.CoreLib]], PubnubPCL]][]
00007f8325e89150   708563     17005512 System.Threading.Timer
00007f8326aada58   708775     17010600 System.Threading.TimerHolder
00007f83255c5290   708988     17015712 System.Object
00007f832b826f38   235225     18818000 System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib],[System.Net.HttpWebRequest, System.Net.Requests]]
00007f8325ba2890       17     33503088 System.Collections.Generic.Dictionary`2+Entry[[System.String, System.Private.CoreLib],[System.String, System.Private.CoreLib]][]
00007f83294d4898   708502     34008096 PubnubApi.EndPoint.TelemetryManager
00007f832a8c9368   470451     37636080 System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib],[System.Boolean, System.Private.CoreLib]]
00007f8325abac58    38012     39857914 System.Byte[]
00007f83266827b8   708749     45359936 System.Threading.TimerCallback
00007f8326682678   708860     68050560 System.Threading.TimerQueueTimer
00007f832567d2e0   740815     68704692 System.String
00007f83294d2820   708502    107692304 PubnubApi.PNConfiguration
Total 7963348 objects

PubNub memory leak detected

The cause of memory leak is public class TelemetryManager : IDisposable.
This class is created by public class Pubnub is case of config.EnableTelemetry == true but will never be disposed.
It can lead to significantly increasing of Number of Active Timers and ultimately lead to memory leak.
image

Also, non-disposed timers can affect monitor tools (e.g. New Relic) -
image

My suggestion is:

  1. Add IDisposable interface to Pubnub class.
  2. Implement Dispose method to clear this.TelemetryManager.

"Spaces" and "AuthorizedUserId" are not considered when granting token

In 6.0.8 release both GrantTokenOperation.AuthorizedUuid and PNTokenPermissionMappingBase.Channels are marked with [Obsolete] attribute and it's recommended to use GrantTokenOperation.AuthorizedUserId and PNTokenPermissionMappingBase.Spaces accordingly. But neither Spaces nor AuthorizedUserId are taken into account when granting access token.

When using Spaces instead of Channel server returns 400 status code with error message This grant contains no permissions. Usage of AuthorizedUserId instead of AuthorizedUuid results in the loss of information about the authorized user in access token (value of authorized_uuid property of parsed access token is null)

Problem with Recursive subscribe

The recursive subscribe in MultiChannelSubscribeRequest can ultimately lead to stack overflow.

I've replaced it in our app with a simple loop, and the chap seeing the error has reported no more problems.

Pubnub C# api "self conflict"

When i try use 2 instances of Pubnub class (one for my channel, one for channel of different company, so i need 2 subscribe keys) sometimes messages cannot be published. Publish function return "ok" but nothing happens.

Occasional failure to connect when using multiple Subscribe + Execute invocations

High-Level Problem

A .NET 8 service application that subscribes to messages from PubNub and, upon upgrade/restart, will occasionally get into a state where it cannot connect to PubNub until the application is restarted again.

Notes

  • The .NET application is .NET 8 (as time of this writing, v8.0.200).
  • Using NuGet PubnubPCL v6.19.7 (latest as of April 16, 2024).
  • Using ReconnectionPolicy repeatedly fails to connect to PubNub.
  • The current nature of the .NET application is to perform multiple Subscribe() + Execute() invocations when an entity from a separate system is "discovered" (e.g. Discover Entity A then perform Subscribe().Channels("entity-A-notification-type1").Execute()).
  • My personal gut feeling is a thread synchronization issue, possibly somewhere around ClientNetworkStatus.RefHttpClient = httpClientNetworkStatus.
  • When I add a project reference to PubnubApiPCL.csproj, I caught this state where, somehow, there is a header with a null key (.NET thread safety issue with HTTP headers?).
    Untitled

Reproduction

I have attached a simple application (from a Windows system). You will need to populate SubscribeKey, AuthKey, and channels with real values. Afterwards, you can run the script run.bat which should build and then re-start the application until the problem eventually reproduces; the output will indicate a failure to connect (ERROR Internet connection problem. Retrying connection Cat=PNNetworkIssuesCategory). I usually have it reproduce within about 30 seconds.
ReproductionApp.zip

The application is fairly straightforward: create the Pubnub instance, perform Subscribe().Channels(...).Execute() multiple times, then wait about 2 seconds for connection messages before exiting.

The sdk retries in 403s leading to huge billings.

Hi,

I thought this issue was already solved but apparently not. In testing I forced the SDK to use the wrong auth key to see what the retry behavior would be and to my surprise you are retrying on all 403s sent by Pubnub creating a huge bill if not careful:

Warning: DateTime: 12/07/2021 01:22:03, Inside SendRequestAndGetJsonResponseHttpClient
Warning: DateTime 12/07/2021 01:22:03 GetTimeWithHttpClient Resp OK
Warning: DateTime 12/07/2021 01:22:03, JSON= {"message":"Forbidden","payload":{"channels":["chanel"]},"error":true,"service":"Access Manager","status":403}
Warning: DateTime 12/07/2021 01:22:03, EXPONENTIAL timerInterval = 7
Warning: DateTime 12/07/2021 01:22:10 MultiplexExceptionHandlerTimerCallback
Warning: DateTime 12/07/2021 01:22:10 MultiplexInternalCallback timetoken = 0
Warning: DateTime 12/07/2021 01:22:10 CheckSocketConnect Entered
Warning: DateTime 12/07/2021 01:22:10 GetTimeWithHttpClient Resp OK
Warning: DateTime 12/07/2021 01:22:10, JSON= {"message":"Forbidden","payload":{"channels":["chanel"]},"error":true,"service":"Access Manager","status":403}
Warning: DateTime 12/07/2021 01:22:10, EXPONENTIAL timerInterval = 15

This is part of the log, I've removed personal information and channel names since I don't want that information on github. But as you can see it keeps retrying on 403s which makes no sense. How can an internal retry logic solve a 403 without being able to acquire keys? This should be left up to the developer.

I thought this was a known issue. I had a support call with Craig Connover when he was helping us build the app, and later with his successor. How come this hasn't been fixed?

PubNub service stops listening after a few days

I have an ASP.NET Core 6 application that's hosted in IIS. In the application I use PubNub 6.13.0 service to subscribe to a channel and listen/respond to incoming requests. The problem is the service stops listening after a while (usually a couple of days). The application works otherwise (handling REST and SignalR requests just fine), but the only way I can get PubNub to work is by Recycling the app pool.

I have the app deployed to about 20 servers at this point (both in AWS and on-prem), and this happens on every single instance. Any idea of what could potentially cause it, or how I could troubleshoot what's causing it, or at the very least hack some workaround? Thanks.

I initialize the service as singleton:

services.AddSingleton<IPubNubService, PubNubService>();

I 'start up' the instance on startup like this:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
   //...
   app.ApplicationServices.GetService<IPubNubService>(); 
}

Here's a simplified view of the PubNubService itself:

public class PubNubService : IPubNubService
{
    public PubNubService()
    {
        _pubNub = new Pubnub(new PNConfiguration(new UserId($"PubNub:UserId"))
        {
            SubscribeKey = config.GetValue<string>("PubNub:SubscribeKey"), 
            PublishKey = config.GetValue<string>("PubNub:PublishKey"), 
        });
        
        _pubNub.Subscribe<string>()
            .Channels(new[] { "PubNub:BroadcastChannel" })
            .Execute();

        _pubNub.AddListener(CreateListener());
    }

    // https://github.com/pubnub/c-sharp/
    // https://www.pubnub.com/docs/sdks/c-sharp/api-reference/configuration
    private SubscribeCallbackExt CreateListener()
    {
        return new SubscribeCallbackExt
        (
            messageCallback: async delegate(Pubnub pnObj, PNMessageResult<object> pubMsg)
            {
                await HandleReceivedMessage(pubMsg);
            },
        );
    }

    rivate async Task HandleReceivedMessage(PNMessageResult<object> pubNubMessage)
    {
        // ...
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.