A very strange phenomenon we’re experiencing: We’r...
# coroutines
u
A very strange phenomenon we’re experiencing: We’re running microservices in Kubernetes. The services are running coroutines. In the test kubernetes cluster, when the tests are finishing, the namespace is deleted. I see that the namespace is deleted and all services were terminated, but then we still see for a pretty long time (tens of minutes) logs messages coming from the coroutines threads. The thread is DefaultDispatcher-worker-1 and the class is kotlinx.coroutines.StandaloneCoroutine. Is it possible that this thread will stay alive when the JVM is down? Or that it will run on a system thread of the k8s node although the container is shut down??? The coroutine due is to update the feature flags status gauge from database
Copy code
init {
  GlobalScope.launch (<http://Dispatchers.IO|Dispatchers.IO>) {
    val logger = LoggerFactory.getLogger(javaClass)
    var exceptionsCounter = 0
    while (true) {
      delay(DELAY_IN_MS_BETWEEN_FLAGS_CHECKS)
      try {
        getFlags()
            .onEach {
              featureFlagsStatusGauge.labels(it.key).set(if (it.value) 1.0 else 0.0)
            }
        exceptionsCounter = 0
      } catch (e: Exception) {
        exceptionsCounter++
        if (exceptionsCounter > 6) logger.warn("Got exception while trying to update feature flags status for $exceptionsCounter times", e)
      }
    }
  }