path-data icon indicating copy to clipboard operation
path-data copied to clipboard

Use `RetryPolicy` to keep SignalR connection alive and replace `List<RealtimeData>` with `ImmutableList<RealtimeData>`

Open persuasive0pest opened this issue 5 months ago • 2 comments

This change can potentially fix high error rate of realtime endpoint.

closes: https://github.com/mrazza/path-data/issues/23

Other than the added logs that will help with future debugging, there are 2 problems this PR would solve:

  • The reconnection is now handled by RetryPolicy, which should avoid the need to listen to the Closed event.
  • Using ImmutableList with ConcurrentDictionary should help with the potential concurrency issues, as addValueFactory may be called multiple times, see link.

There are 2 problems this PR would not solve for now:

  • It seems reading from ConcurrentDictionary using GetRealtimeData method is sometimes not very performant, it maybe due to GRPC server itself but I need more time to investigate, the GRPC connection simply stuck and can take long enough for the gateway to timeout the connection.
  • It seems using ConcurrentDictionary to store HubConnection suffer from similar issue as the problem mentioned above, as addValueFactory may be called multiple times however since it is not used as often as the ConcurrentDictionary used to store List<RealtimeData> I never observed any problem in production.

There are 1 problem I have no clue how to solve:

  • It seems PATH sometimes simply don't feed messages for trains to a certain direction for a certain station, see a screenshot from official app for evidence. This result in trains missing from upcomingTrains array.

Screenshot_20240220_081414

Recent monitoring from my own instance: image Seems to be relatively stable after the changes.

persuasive0pest avatar Feb 21 '24 01:02 persuasive0pest