Commit 47e0be1
authored
Fix keepalive logic (#50)
This PR fixes grpc/grpc-swift#2095.
## Motivation
As per the gRPC specification, the server must keep track of pings from
each client, and if they go over a threshold, we must send a GOAWAY
frame and close the connection. We must reset the number of ping strikes
every time the server writes a headers or data frame. However, there is
a bug in the current keepalive implementation and we are not properly
keeping track of when header/data frames are written, so we never reset
the strikes, causing the server to always end up closing connections
when keepalive pings are enabled.
There was also a second bug where the GOAWAY frame wasn't actually sent
to the client because we were closing the connection straight away, and
the packet never made it out.
## Modifications
This PR fixes a couple of bugs:
- It keeps track of the appropriate FrameStats as described above
- It delays the channel close after sending the GOAWAY packet by a tick
to make sure it gets flushed and delivered to the client
## Results
Fewer bugs!1 parent 289c0bc commit 47e0be1
File tree
6 files changed
+136
-12
lines changed- Sources/GRPCNIOTransportCore
- Internal
- Server
- Connection
- Tests/GRPCNIOTransportCoreTests
- Client/Connection/Utilities
- Server
6 files changed
+136
-12
lines changedLines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
74 | 78 | | |
75 | 79 | | |
76 | 80 | | |
| |||
86 | 90 | | |
87 | 91 | | |
88 | 92 | | |
89 | | - | |
| 93 | + | |
| 94 | + | |
90 | 95 | | |
91 | 96 | | |
92 | 97 | | |
| |||
Lines changed: 9 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | | - | |
| 126 | + | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| |||
609 | 609 | | |
610 | 610 | | |
611 | 611 | | |
612 | | - | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
613 | 619 | | |
614 | 620 | | |
615 | 621 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| 60 | + | |
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
| |||
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
| 72 | + | |
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
| |||
136 | 140 | | |
137 | 141 | | |
138 | 142 | | |
| 143 | + | |
139 | 144 | | |
140 | 145 | | |
| 146 | + | |
141 | 147 | | |
142 | 148 | | |
143 | 149 | | |
144 | 150 | | |
145 | 151 | | |
| 152 | + | |
146 | 153 | | |
147 | 154 | | |
148 | 155 | | |
| |||
261 | 268 | | |
262 | 269 | | |
263 | 270 | | |
| 271 | + | |
264 | 272 | | |
265 | 273 | | |
266 | 274 | | |
| |||
270 | 278 | | |
271 | 279 | | |
272 | 280 | | |
| 281 | + | |
273 | 282 | | |
274 | 283 | | |
275 | 284 | | |
| |||
Lines changed: 13 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
117 | 128 | | |
118 | 129 | | |
119 | 130 | | |
120 | 131 | | |
121 | 132 | | |
122 | | - | |
| 133 | + | |
| 134 | + | |
123 | 135 | | |
124 | 136 | | |
125 | 137 | | |
| |||
Lines changed: 13 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
73 | 84 | | |
74 | 85 | | |
75 | 86 | | |
76 | 87 | | |
77 | 88 | | |
78 | | - | |
| 89 | + | |
| 90 | + | |
79 | 91 | | |
80 | 92 | | |
81 | 93 | | |
| |||
Lines changed: 86 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
36 | 48 | | |
37 | 49 | | |
38 | 50 | | |
39 | 51 | | |
40 | 52 | | |
41 | 53 | | |
| 54 | + | |
42 | 55 | | |
43 | 56 | | |
44 | 57 | | |
| |||
974 | 987 | | |
975 | 988 | | |
976 | 989 | | |
977 | | - | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
978 | 996 | | |
979 | 997 | | |
980 | 998 | | |
981 | 999 | | |
982 | 1000 | | |
983 | 1001 | | |
984 | | - | |
985 | | - | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
986 | 1015 | | |
987 | 1016 | | |
988 | 1017 | | |
989 | 1018 | | |
990 | 1019 | | |
| 1020 | + | |
991 | 1021 | | |
992 | 1022 | | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
993 | 1028 | | |
994 | 1029 | | |
995 | 1030 | | |
996 | 1031 | | |
997 | 1032 | | |
998 | | - | |
| 1033 | + | |
999 | 1034 | | |
1000 | 1035 | | |
1001 | 1036 | | |
| |||
1011 | 1046 | | |
1012 | 1047 | | |
1013 | 1048 | | |
1014 | | - | |
| 1049 | + | |
1015 | 1050 | | |
1016 | 1051 | | |
1017 | 1052 | | |
| |||
1028 | 1063 | | |
1029 | 1064 | | |
1030 | 1065 | | |
1031 | | - | |
| 1066 | + | |
1032 | 1067 | | |
1033 | 1068 | | |
1034 | 1069 | | |
| |||
1045 | 1080 | | |
1046 | 1081 | | |
1047 | 1082 | | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
1048 | 1128 | | |
1049 | 1129 | | |
1050 | 1130 | | |
| |||
0 commit comments