Getting j.n.c.ClosedChannelException continuously at the time of token creation

We are having the below code snippet with one of it’s API call:

// Token generation

val scnT1 = scenario("Token Generation Fulfillment")
      .exec(http("Get Token")
        .post("https://login.microsoftonline.com/(valid subscription key)/oauth2/token")
        .header("Content-Type", "application/x-www-form-urlencoded")
        .formParam("client_id", service_id)
        .formParam("client_secret", service_secret)
        .formParam("grant_type", "client_credentials")
        .formParam("resource", "***") // valid resource id
        .check(jsonPath("$.access_token").saveAs("authToken4"))
      ).exitHereIfFailed
      .exec{session => { authToken = session("authToken4").as[String]
        println(s"Token generated for fulfillment")
        session
}
}

// API call

object invokeFulfillmentCalls {

    var apiheaders = Map("X-Boomi-Debug" ->"false","Content-Type" -> "application/json","Authorization" -> "Bearer ${authToken}","Ocp-Apim-Subscription-Key" -> "***")
    var apimethod = exec(session => session.set("authToken",authToken4)).feed(msorderid)
     
     // get calls
  
      .exec(http("PickReport")
        .get("https://svt2apigw.cmltd.net.au/col/ocado/fulfillment/v1/pickreport/SVT-FID-PR-20-${msorderid}")
        .headers(apiheaders)
        .check(status is 200)
      )
}

Whenever our environment is hitting the APIM URL (Either for MRL or Boomi) from Gatling Script, which is running inside ArgoCD, we are getting j.n.c.ClosedChannelException for 100% requests. We are able to hit the same URL from postman installed on Local VPC.

For the below URL the same thing is working which is generating the token and pushing the events to the Event hub:

object inject_DR_EH_500 {
    var apiheaders = Map("Content-Type" -> "application/atom+xml;type=entry;charset=utf-8","Authorization" -> "Bearer ${authTokenMs}")
    var apimethod = exec(session => session.set("authTokenMs",authTokenMs)).feed(msorderid).feed(timestampFeeder)
      .exec(http("Delivery Report FSMev EH 500 Items")
        .post("https://EVH-OTF-***-***-AUE.***.windows.net/***/messages") // pushing events to event hub
        .headers(apiheaders)
        .body(ElFileBody("src/***/resources/data/***.json")).asJson
        .check(status is 201)
      )
  }

We have been in contact with our DevOps team, and they have tested CURL operations in the Argo CD Gatling PODs, which are functioning properly. They informed us that there is no issue on the server side, so we need to inspect our script. This error appears to be new to us, as the code was working previously but suddenly started throwing a Closed Channel exception.

The server is forcefully closing the socket without sending a response first.

There’s no way to tell being able to debug your test and analyze your network traffic and be familiar with your infrastructure.
Sorry but we can’t help with that unless you contract for consulting.

This could be many things, including:

  • incorrect credentials
  • being blocked at the network level, eg firewall/security group
  • server requiring mTLS

Note: .header("Content-Type", "application/x-www-form-urlencoded") is useless, Gatling will add it for you as you’re using formParam.

Can we do anything in the script to get better output for error.

No. From Gatling’s client side, the only thing happening is that the server is abruptly closing the socket without first sending a response that could provide more information.

The place you have to investigate is the server.

Can you please check the query once more? I have made some edits and hope it will help you understand my query better.