question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

400 Bad Request response while retrieving recorded requests (java.util.concurrent.TimeoutException)

See original GitHub issue

Describe the issue When trying to retrieve recorded requests (https://www.mock-server.com/mock_server/debugging_issues.html#retrieving_recorded_requests), mock-server hangs for a moment and returns 400 Bad Request response. Internally Mock Server fails to handle the request with java.util.concurrent.TimeoutException.

What you are trying to do I am trying to retrieve recorded request to introspect the request sent by the service being tested.

MockServer version 5.11.2 (Docker image with latest label)

To Reproduce Steps to reproduce the issue:

  1. MockServer run with Docker image
  2. Expectation:
PUT /mockserver/expectation
{"httpRequest": {"path": "/emails/messages/"},
  "httpResponse": {"body": {"/1234/": "boo"}}
}
  1. What error you saw
PUT /mockserver/retrieve?type=REQUESTS
{"path": "/emails/messages/"}

response:
HTTP 400 
Exception retrieving state for {\n  "method" : "PUT",\n  "path" : "/mockserver/retrieve",\n  "queryStringParameters" : {\n    "type" : [ "REQUESTS" ]\n  },\n  "headers" : {\n    "Host" : [ "myservice-mock:1080" ],\n    "User-Agent" : [ "python-requests/2.25.1" ],\n    "Accept-Encoding" : [ "gzip, deflate" ],\n    "Accept" : [ "*/*" ],\n    "Connection" : [ "keep-alive" ],\n    "Content-Length" : [ "29" ],\n    "Content-Type" : [ "application/json" ]\n  },\n  "keepAlive" : true,\n  "secure" : false,\n  "body" : {\n    "contentType" : "application/json",\n    "type" : "JSON",\n    "json" : {\n      "path" : "/emails/messages/"\n    }\n  }\n}

Expected behaviour 3. Receive recorded requests

{"path": "/emails/messages/"}

response:
HTTP 200 
[…]

MockServer Log DEBUG level:

2021-11-10 12:35:27 5.11.2 SEVERE 1080 exception handling request:

   {
     "method" : "PUT",
     "path" : "/mockserver/retrieve",
     "queryStringParameters" : {
       "type" : [ "REQUESTS" ]
     },
     "headers" : {
       "Host" : [ "panoptic-mock:1080" ],
       "User-Agent" : [ "python-requests/2.25.1" ],
       "Accept-Encoding" : [ "gzip, deflate" ],
       "Accept" : [ "*/*" ],
       "Connection" : [ "keep-alive" ],
       "Content-Length" : [ "47" ],
       "Content-Type" : [ "application/json" ]
     },
     "keepAlive" : true,
     "secure" : false,
     "body" : {
       "path" : "/emails/messages/",
       "method" : "POST"
     }
   }

  error:



 java.util.concurrent.TimeoutException
 	at java.base/java.util.concurrent.CompletableFuture.timedGet(CompletableFuture.java:1886)
 	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2021)
 	at org.mockserver.mock.HttpState.retrieve(HttpState.java:475)
 	at org.mockserver.mock.HttpState.handle(HttpState.java:607)
 	at org.mockserver.netty.HttpRequestHandler.channelRead0(HttpRequestHandler.java:92)
 	at org.mockserver.netty.HttpRequestHandler.channelRead0(HttpRequestHandler.java:48)
 	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
 	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
 	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at org.mockserver.dashboard.DashboardWebSocketHandler.channelRead(DashboardWebSocketHandler.java:140)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at org.mockserver.closurecallback.websocketregistry.CallbackWebSocketServerHandler.channelRead(CallbackWebSocketServerHandler.java:55)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
 	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
 	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
 	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at org.mockserver.netty.unification.PortUnificationHandler.switchToHttp(PortUnificationHandler.java:260)
 	at org.mockserver.netty.unification.PortUnificationHandler.decode(PortUnificationHandler.java:138)
 	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:501)
 	at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:366)
 	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
 	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
 	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
 	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
 	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
 	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
 	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
 	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
 	at java.base/java.lang.Thread.run(Thread.java:834)

 2021-11-10 12:35:27 5.11.2 SEVERE 1080 exception processing {
   "method" : "PUT",
   "path" : "/mockserver/retrieve",
   "queryStringParameters" : {
     "type" : [ "REQUESTS" ]
   },
   "headers" : {
     "Host" : [ "panoptic-mock:1080" ],
     "User-Agent" : [ "python-requests/2.25.1" ],
     "Accept-Encoding" : [ "gzip, deflate" ],
     "Accept" : [ "*/*" ],
     "Connection" : [ "keep-alive" ],
     "Content-Length" : [ "47" ],
     "Content-Type" : [ "application/json" ]
   },
   "keepAlive" : true,
   "secure" : false,
   "body" : {
     "contentType" : "application/json",
     "type" : "JSON",
     "json" : {
       "path" : "/emails/messages/",
       "method" : "POST"
     }
   }
 }
 java.lang.RuntimeException: Exception retrieving state for {
   "method" : "PUT",
   "path" : "/mockserver/retrieve",
   "queryStringParameters" : {
     "type" : [ "REQUESTS" ]
   },
   "headers" : {
     "Host" : [ "panoptic-mock:1080" ],
     "User-Agent" : [ "python-requests/2.25.1" ],
     "Accept-Encoding" : [ "gzip, deflate" ],
     "Accept" : [ "*/*" ],
     "Connection" : [ "keep-alive" ],
     "Content-Length" : [ "47" ],
     "Content-Type" : [ "application/json" ]
   },
   "keepAlive" : true,
   "secure" : false,
   "body" : {
     "contentType" : "application/json",
     "type" : "JSON",
     "json" : {
       "path" : "/emails/messages/",
       "method" : "POST"
     }
   }
 }
 	at org.mockserver.mock.HttpState.retrieve(HttpState.java:485)
 	at org.mockserver.mock.HttpState.handle(HttpState.java:607)
 	at org.mockserver.netty.HttpRequestHandler.channelRead0(HttpRequestHandler.java:92)
 	at org.mockserver.netty.HttpRequestHandler.channelRead0(HttpRequestHandler.java:48)
 	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
 	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
 	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at org.mockserver.dashboard.DashboardWebSocketHandler.channelRead(DashboardWebSocketHandler.java:140)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at org.mockserver.closurecallback.websocketregistry.CallbackWebSocketServerHandler.channelRead(CallbackWebSocketServerHandler.java:55)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
 	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
 	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
 	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at org.mockserver.netty.unification.PortUnificationHandler.switchToHttp(PortUnificationHandler.java:260)
 	at org.mockserver.netty.unification.PortUnificationHandler.decode(PortUnificationHandler.java:138)
 	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:501)
 	at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:366)
 	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
 	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
 	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
 	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
 	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
 	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
 	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
 	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
 	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
 	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
 	at java.base/java.lang.Thread.run(Thread.java:834)
 Caused by: java.util.concurrent.TimeoutException
 	at java.base/java.util.concurrent.CompletableFuture.timedGet(CompletableFuture.java:1886)
 	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2021)
 	at org.mockserver.mock.HttpState.retrieve(HttpState.java:475)
 	... 56 more

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:12

github_iconTop GitHub Comments

2reactions
m-aciekcommented, Mar 24, 2022

Thanks, I pulled 5.13.1 this time. And it seems to fix the issue 🎉 . I have 100% success rate so far (4 runs).

22-03-24 15:44:47 5.13.1-SNAPSHOT INFO retrieved requests in json that match:

{
"path" : "/emails/messages/"
}

Thank you very much for your work and help on it!

1reaction
jamesdbloomcommented, Mar 24, 2022

It looks like the snapshot docker tag doesn’t contain the latest snapshot it is using 5.11.3-SNAPSHOT (as shown in your logs) but it should be 5.13.1-SNAPSHOT.

I’ve tracked down the cause and it turns out sonatype (behind maven central) has an open bug for not updating the LATEST tag for snapshots, as shown in the metadata xml downloaded from maven central snapshot repo:

<?xml version="1.0" encoding="UTF-8"?>
<metadata>
   <groupId>org.mock-server</groupId>
   <artifactId>mockserver-netty</artifactId>
   <versioning>
      <latest>5.11.3-SNAPSHOT</latest>
      <release />
      <versions>
         <version>3.7.1-SNAPSHOT</version>
         <version>3.7.2-SNAPSHOT</version>
         <version>3.8.3-SNAPSHOT</version>
         <version>3.9.18-SNAPSHOT</version>
         <version>3.9.19-SNAPSHOT</version>
         <version>3.10.9-SNAPSHOT</version>
         <version>4.1.1-SNAPSHOT</version>
         <version>5.2.4-SNAPSHOT</version>
         <version>5.3.1-SNAPSHOT</version>
         <version>5.4.2-SNAPSHOT</version>
         <version>5.5.2-SNAPSHOT</version>
         <version>5.5.5-SNAPSHOT</version>
         <version>5.6.2-SNAPSHOT</version>
         <version>5.7.3-SNAPSHOT</version>
         <version>5.8.2-SNAPSHOT</version>
         <version>5.9.1-SNAPSHOT</version>
         <version>5.10.1-SNAPSHOT</version>
         <version>5.11.3-SNAPSHOT</version>
         <version>5.12.1-SNAPSHOT</version>
         <version>5.13.1-SNAPSHOT</version>
      </versions>
      <lastUpdated>20220324065126</lastUpdated>
   </versioning>
</metadata>

I’ve committed a hack fix for this to explicitly specify the latest snapshot version.

Can you please pull the latest snapshot tag again and retry:

docker pull mockserver/mockserver:snapshot

When you run you should see each log event starts has 5.13.1-SNAPSHOT, for example:

docker run mockserver/mockserver:snapshot
2022-03-24 14:28:16 5.13.1-SNAPSHOT INFO using environment variables:

  [
  	SERVER_PORT=1080
  ]

 and system properties:

  [
  	mockserver.propertyFile=/config/mockserver.properties
  ]

 and command line options:

  [
  	
  ]
 
2022-03-24 14:28:17 5.13.1-SNAPSHOT INFO logger level is INFO, change using:
 - 'ConfigurationProperties.logLevel(String level)' in Java code,
 - '-logLevel' command line argument,
 - 'mockserver.logLevel' JVM system property or,
 - 'mockserver.logLevel' property value in 'mockserver.properties' 
2022-03-24 14:28:17 5.13.1-SNAPSHOT INFO 1080 started on port: 1080 
Read more comments on GitHub >

github_iconTop Results From Across the Web

java.util.concurrent.TimeoutException Error - Stack Overflow
1 Answer 1 ... Based on the stack trace you've shared, the TimeoutException has been thrown from the invocation of the blocking method...
Read more >
400 Bad Request“ return when POST Rest API call to ... - AskF5
To work around this issue, you can restart the restjavad service. Login to tmsh. Run below command to restart restjavad: restart sys service ......
Read more >
Error handling with DynamoDB - AWS Documentation
An HTTP 400 status code indicates a problem with your request, such as authentication failure, missing required parameters, or exceeding a table's provisioned ......
Read more >
Solved: 400: Bad Request : The request could not be comple...
A 400 means that the request was malformed. In other words, the data stream sent by the client to ...
Read more >
3. Resolved and Known Issues Red Hat JBoss Enterprise ...
If the remote naming context object was closed when done, the client logged the error shown below, because the ejb-client context was already...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found