John Colvin fd9892c6b6 fix: Prevent raw_pb_callback premature garbage collection
Bugs (fixed):
   * Startup crash w/ error message: "A callback was made on a garbage
     collected delegate of type ApiNativeMethods.raw_pb_callback"

   Cause: The callback is only referenced in unmanaged c++. Without references
   in managed code, the Garbage Collector deems the delegate eligible for
   collection before the callback has finished execution.

   Note: The original solution forced a reference in managed code by storing it
   in a class-member 'keepalive' dictionary, whose life isn't bound to the
   [synchronous] scope of the 'send' method. The callback would then remove
   itself from the dictionary in its last line of code. While this reduced the
   chance of such an error occurring, occassional crashes persisted
   (particularly in low-bandwidth environments). I suspect the frequency at
   which garbage-collector threads run is inversely related to the frequency
   at which data arrives from the server, as the latter triggers execution of
   higher-priority threads.

   Steps to repro:
      1. Insert a Thread.Sleep statement (1000 ms should be sufficient) after
         the call that removes the last reference to the delegate (i.e., make
         the thread sleep for a significant amount of time in the callback
         AFTER it becomes eligible for garbage collection).

      2. Build, run, and observe crash on startup.

   Solution: Wrap the callback in another class, and store the wrapper
   in the dictionary rather than the callback itself. The reason why this
   works isn't totally clear, however its effectiveness has been verified
   with the repro (described above).
2022-12-23 11:25:07 -05:00
2021-09-06 19:35:30 -04:00
2022-12-09 00:47:47 -05:00
2022-09-21 00:17:31 -05:00
2021-12-09 11:40:49 -05:00
2022-10-10 11:01:59 -04:00
2022-01-23 16:15:11 -05:00
2022-09-21 00:14:38 -05:00
2022-09-08 22:07:05 -04:00
2022-05-02 12:28:56 -04:00
2019-11-14 17:44:24 -05:00
S
Description
No description provided
182 MiB
0 Stars 1 Watchers 0 Forks
Languages
C++ 54.9%
C# 39.2%
CSS 2.7%
F# 1.3%
Python 0.8%
Other 0.9%