Skip to content

Fix race condition in grpc_tsi_alts_shutdown#14296

Merged
jiangtaoli2016 merged 1 commit intogrpc:masterfrom
yihuazhang:FIX_ALTS_SHUTDOWN
Feb 7, 2018
Merged

Fix race condition in grpc_tsi_alts_shutdown#14296
jiangtaoli2016 merged 1 commit intogrpc:masterfrom
yihuazhang:FIX_ALTS_SHUTDOWN

Conversation

@yihuazhang
Copy link
Copy Markdown
Contributor

In the original implementation, cq is destroyed before being drained which resulted in a race condition between TSI and main threads. That is, it was possible for the main thread to invoke grpc_completion_queue_destroy() on cq while the TSI thread is still actively using it. The correct implementation is cq should be drained before grpc_completion_queue_destroy() gets invoked. We need to call grpc_completion_queue_shutdown(), wait for TSI thread to finish working on it, then signal the main thread to continue with the destroy.

@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE                                               FILE SIZE
 ++++++++++++++ GROWING                                 ++++++++++++++
  +0.0%    +196 [None]                                     +884  +0.0%
      +0.0%    +132 [Unmapped]                                 +884  +0.0%
       +88%     +56 g_alts_resource                               0  [ = ]
      +0.7%      +8 [None]                                        0  [ = ]
  +161%    +188 src/core/tsi/alts_transport_security.cc    +188  +161%
      +133%     +92 grpc_tsi_alts_shutdown                      +92  +133%
      [NEW]     +51 grpc_tsi_alts_signal_for_cq_destroy         +51  [NEW]
      +312%     +25 [Unmapped]                                  +25  +312%
       +62%     +20 grpc_tsi_alts_init                          +20   +62%

  +0.0%    +384 TOTAL                                   +1.05Ki  +0.0%


****************************************************************

libgrpc++.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use the following to avoid goto.
if (g_alts_resource.cq != nullptr) {
...
}

@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE                                               FILE SIZE
 ++++++++++++++ GROWING                                 ++++++++++++++
  +0.0%    +196 [None]                                     +852  +0.0%
      +0.0%    +132 [Unmapped]                                 +852  +0.0%
       +88%     +56 g_alts_resource                               0  [ = ]
      +0.7%      +8 [None]                                        0  [ = ]
  +161%    +188 src/core/tsi/alts_transport_security.cc    +188  +161%
      +133%     +92 grpc_tsi_alts_shutdown                      +92  +133%
      [NEW]     +51 grpc_tsi_alts_signal_for_cq_destroy         +51  [NEW]
      +312%     +25 [Unmapped]                                  +25  +312%
       +62%     +20 grpc_tsi_alts_init                          +20   +62%

  +0.0%    +384 TOTAL                                   +1.02Ki  +0.0%


****************************************************************

libgrpc++.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]



Copy link
Copy Markdown

@jiangtaoli2016 jiangtaoli2016 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Could you squash the commits?

@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE                                               FILE SIZE
 ++++++++++++++ GROWING                                 ++++++++++++++
  +0.0%    +196 [None]                                     +852  +0.0%
      +0.0%    +132 [Unmapped]                                 +852  +0.0%
       +88%     +56 g_alts_resource                               0  [ = ]
      +0.7%      +8 [None]                                        0  [ = ]
  +161%    +188 src/core/tsi/alts_transport_security.cc    +188  +161%
      +133%     +92 grpc_tsi_alts_shutdown                      +92  +133%
      [NEW]     +51 grpc_tsi_alts_signal_for_cq_destroy         +51  [NEW]
      +312%     +25 [Unmapped]                                  +25  +312%
       +62%     +20 grpc_tsi_alts_init                          +20   +62%

  +0.0%    +384 TOTAL                                   +1.02Ki  +0.0%


****************************************************************

libgrpc++.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE                                               FILE SIZE
 ++++++++++++++ GROWING                                 ++++++++++++++
  +0.0%    +196 [None]                                     +852  +0.0%
      +0.0%    +132 [Unmapped]                                 +852  +0.0%
       +88%     +56 g_alts_resource                               0  [ = ]
      +0.7%      +8 [None]                                        0  [ = ]
  +161%    +188 src/core/tsi/alts_transport_security.cc    +188  +161%
      +133%     +92 grpc_tsi_alts_shutdown                      +92  +133%
      [NEW]     +51 grpc_tsi_alts_signal_for_cq_destroy         +51  [NEW]
      +312%     +25 [Unmapped]                                  +25  +312%
       +62%     +20 grpc_tsi_alts_init                          +20   +62%

  +0.0%    +384 TOTAL                                   +1.02Ki  +0.0%


****************************************************************

libgrpc++.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

1 similar comment
@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE                                               FILE SIZE
 ++++++++++++++ GROWING                                 ++++++++++++++
  +0.0%    +164 [None]                                     +844  +0.0%
      +0.0%    +100 [Unmapped]                                 +844  +0.0%
       +88%     +56 g_alts_resource                               0  [ = ]
      +0.7%      +8 [None]                                        0  [ = ]
  +161%    +188 src/core/tsi/alts_transport_security.cc    +188  +161%
      +133%     +92 grpc_tsi_alts_shutdown                      +92  +133%
      [NEW]     +51 grpc_tsi_alts_signal_for_cq_destroy         +51  [NEW]
      +312%     +25 [Unmapped]                                  +25  +312%
       +62%     +20 grpc_tsi_alts_init                          +20   +62%

  +0.0%    +352 TOTAL                                   +1.01Ki  +0.0%


****************************************************************

libgrpc++.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE                                               FILE SIZE
 ++++++++++++++ GROWING                                 ++++++++++++++
  +0.0%    +164 [None]                                     +852  +0.0%
      +0.0%    +100 [Unmapped]                                 +852  +0.0%
       +88%     +56 g_alts_resource                               0  [ = ]
      +0.7%      +8 [None]                                        0  [ = ]
  +161%    +188 src/core/tsi/alts_transport_security.cc    +188  +161%
      +133%     +92 grpc_tsi_alts_shutdown                      +92  +133%
      [NEW]     +51 grpc_tsi_alts_signal_for_cq_destroy         +51  [NEW]
      +312%     +25 [Unmapped]                                  +25  +312%
       +62%     +20 grpc_tsi_alts_init                          +20   +62%

  +0.0%    +352 TOTAL                                   +1.02Ki  +0.0%


****************************************************************

libgrpc++.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

Corrupt JSON data (indicates timeout or crash): 
    bm_fullstack_streaming_pump.BM_PumpStreamServerToClient_SockPair__512.opt.new: 1
    bm_fullstack_streaming_pump.BM_PumpStreamServerToClient_SockPair__512.counters.new: 1


[microbenchmarks] No significant performance differences

@yihuazhang
Copy link
Copy Markdown
Contributor Author

It seems the errors are not related to this PR.

@jiangtaoli2016 jiangtaoli2016 merged commit fdc10b6 into grpc:master Feb 7, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants