File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
src/WebJobs.Script.Grpc/Server Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 3
3
4
4
using System ;
5
5
using System . Linq ;
6
+ using System . Threading ;
6
7
using System . Threading . Tasks ;
7
8
using Grpc . Core ;
8
9
using Microsoft . Azure . WebJobs . Script . Abstractions ;
@@ -12,6 +13,7 @@ namespace Microsoft.Azure.WebJobs.Script.Grpc
12
13
{
13
14
public class GrpcServer : IRpcServer , IDisposable
14
15
{
16
+ private int _shutdown = 0 ;
15
17
private Server _server ;
16
18
private bool _disposed = false ;
17
19
public const int MaxMessageLengthBytes = 128 * 1024 * 1024 ;
@@ -36,7 +38,16 @@ public Task StartAsync()
36
38
return Task . CompletedTask ;
37
39
}
38
40
39
- public Task ShutdownAsync ( ) => _server . ShutdownAsync ( ) ;
41
+ public Task ShutdownAsync ( )
42
+ {
43
+ // The Grpc server will throw if it is shutdown multiple times.
44
+ if ( Interlocked . CompareExchange ( ref _shutdown , 1 , 0 ) == 0 )
45
+ {
46
+ return _server . ShutdownAsync ( ) ;
47
+ }
48
+
49
+ return Task . CompletedTask ;
50
+ }
40
51
41
52
public Task KillAsync ( ) => _server . KillAsync ( ) ;
42
53
@@ -46,7 +57,7 @@ protected virtual void Dispose(bool disposing)
46
57
{
47
58
if ( disposing )
48
59
{
49
- _server . ShutdownAsync ( ) ;
60
+ ShutdownAsync ( ) ;
50
61
}
51
62
_disposed = true ;
52
63
}
You can’t perform that action at this time.
0 commit comments