Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# SDK 2.0.0-preview2 stops working after 1 hour #9

Closed
kspearrin opened this issue Aug 6, 2018 · 3 comments
Closed

C# SDK 2.0.0-preview2 stops working after 1 hour #9

kspearrin opened this issue Aug 6, 2018 · 3 comments

Comments

@kspearrin
Copy link

I am trying out the new 2.0.0-preview2 available on nuget in a ASP.NET Core 2.1 application on netcoreapp2.1. This seems to work fine as a drop in replacement for 1.0.9 without any breaking changes.

In my application, NotificationHubClient is initialized as a properly of a singleton instance. I notice that after ~1 hour of the application running, any NotificationHubClient functions that are invoked no longer work. My application does not throw any errors, but all activity to my Notification Hub ceases (confirmed by looking at metrics in the Azure portal) and I no longer get push notifications to my apps. If I restart the server (causing the singleton instance to new again) things again start working for ~1 hour and then stop again.

Due to the nature of the consistent 1 hour lifetime of things working, I suspect that the NotificationHubClient instance is not renewing it's SAS token or something that has a 1 hour lifetime. To workaround this problem I now keep track of internal 30 minute timer where I new the NotificationHubClient up again every 30 minutes. Doing this resolves the problem.

@mpodwysocki
Copy link
Contributor

@kspearrin We are unable to reproduce this particular issue. Can you give us a full repro of the issue in a small sample application?

@kspearrin
Copy link
Author

Are you using 2.0.0-preview2? I am guessing that it may have been resolved in 2.0.0 proper if you can no longer reproduce the issue.

@brannon brannon transferred this issue from Azure/azure-notificationhubs Nov 14, 2018
kmiecikt added a commit that referenced this issue Nov 16, 2018
The `SharedAccessSignatureTokenProvider` creates SAS tokens with 20-minute expiration time by default. To avoid re-creating tokens with each request, it uses memory cache with 1-minute expiration time. However, the memory cache uses sliding expiration window, so if the token is accessed every minute (or more frequently), the token is never removed from the cache and after 20 minutes it is rejected by the backend.

The fix contains two changes:
1. The in-memory cache uses absolute expiration time instead of sliding expiration window.
2. The in-memory cache expiration time is set to SAS token expiration time minus 2 minutes. That should give us enough time to refresh the token and have some safety margin for potential clock skew in the cloud.
kmiecikt added a commit that referenced this issue Nov 16, 2018
The `SharedAccessSignatureTokenProvider` creates SAS tokens with 20-minute expiration time by default. To avoid re-creating tokens with each request, it uses memory cache with 1-minute expiration time. However, the memory cache uses sliding expiration window, so if the token is accessed every minute (or more frequently), the token is never removed from the cache and after 20 minutes it is rejected by the backend.

The fix contains two changes:
1. The in-memory cache uses absolute expiration time instead of sliding expiration window.
2. The in-memory cache expiration time is set to SAS token expiration time minus 2 minutes. That should give us enough time to refresh the token and have some safety margin for potential clock skew in the cloud.
mpodwysocki pushed a commit that referenced this issue Nov 16, 2018
* Fixes issue #9: C# SDK stops working after 20 minutes

The `SharedAccessSignatureTokenProvider` creates SAS tokens with 20-minute expiration time by default. To avoid re-creating tokens with each request, it uses memory cache with 1-minute expiration time. However, the memory cache uses sliding expiration window, so if the token is accessed every minute (or more frequently), the token is never removed from the cache and after 20 minutes it is rejected by the backend.

The fix contains two changes:
1. The in-memory cache uses absolute expiration time instead of sliding expiration window.
2. The in-memory cache expiration time is set to SAS token expiration time minus 2 minutes. That should give us enough time to refresh the token and have some safety margin for potential clock skew in the cloud.

* Increasing version number and updating release notes
@mpodwysocki
Copy link
Contributor

@kspearrin closed as per #13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants