You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -151,16 +156,30 @@ internal class GoogleAuthManagerJvm : GoogleAuthManager {
151
156
)
152
157
}
153
158
154
-
Logger.d("Shutting down server")
155
-
server?.stop(1000, 1000)
156
-
scope.cancel()
159
+
// 🔁 Then shutdown outside of the Ktor pipeline
160
+
performShutdownCleanup()
157
161
158
162
}
159
163
}
160
164
}.start(wait =false)
161
165
return server
162
166
}
163
167
168
+
privatefunperformShutdownCleanup() {
169
+
scope.launch {
170
+
try {
171
+
delay(500) // wait for response to be sent
172
+
Logger.d("Shutting down server")
173
+
server?.stop(1000, 1000) // Stop the server gracefully
174
+
175
+
scope.cancel()
176
+
} catch (e:Exception) {
177
+
Logger.e("Error shutting down server: ${e.message}")
178
+
scope.cancel() // Ensure scope is cancelled even if there's an error
179
+
}
180
+
}
181
+
}
182
+
164
183
privatefunlaunchGoogleSignIn() {
165
184
166
185
try {
@@ -182,16 +201,15 @@ internal class GoogleAuthManagerJvm : GoogleAuthManager {
182
201
}
183
202
184
203
// Start the HTTP server in a separate thread, otherwise it will block the ui
204
+
// We need to reinitialize the scope, otherwise it will throw exception second time becoz we are cancelling the scope after stopping the server and cancelled scope can not be used to launch coroutine again without recreating new scope
205
+
scope =CoroutineScope(Dispatchers.IO)
185
206
scope.launch {
186
207
server = startHttpServer(flow)
187
-
}.invokeOnCompletion {
188
-
Logger.d("invokeOnCompletion called")
189
-
scope.cancel()
190
208
}
191
209
} catch (e:Exception) {
192
210
e.printStackTrace()
211
+
Logger.e("Not able to start the server: ${e.message.toString()}")
0 commit comments