softwaremill / sttp

The Scala HTTP client you always wanted!
https://sttp.softwaremill.com
Apache License 2.0
1.46k stars 309 forks source link

Error (Resource leak) #371

Closed camhobbs closed 4 years ago

camhobbs commented 4 years ago

Hi,

I am getting the follow error on Ubuntu 19.04 (but works fine on my desktop, just not remote server).

[warn] Thread[Thread-1,5,main] loading sttp.model.internal.UriCompatibility$ after test or run has completed. This is a likely resource leak

How can I fix it?

camhobbs commented 4 years ago
    // threadCount is 100
    val request = basicRequest.get(uri"https://cameronhobbs.net/lookup?username=test")
    implicit val backend = HttpURLConnectionBackend()

    for (i <- 1 to threadCount) {
      val thread = new Thread {
        override def run(): Unit = {
          while(true) {
            counter.incrementAndGet()
            val response = request.send()

            if(response.body.toString.contains("\"test\":false")) {
              test(robot)
            }
          }
        }
      }
      thread.start();
    }
camhobbs commented 4 years ago

My lookup endpoint is built on top of an API, and will change JSON output to include {"test":false} at a certain point in time, and I want to call my test() function as soon as the json response changes

adamw commented 4 years ago

is this in sbt? which version? or what test framework?

adamw commented 4 years ago

Maybe that's because you are starting background requests (using thread.start()), their logic continues, but the test method completes. Then the test framework detects that the classloader still loads new classes (triggered by the background threads), and reports an error?

adamw commented 4 years ago

Closing as the issue cannot be reproduced / inactivity