0

My spring MVC controller is being called twice. The most annoying thing is that it's not deterministic, some times it happens some times not. The instance of the controller bean is the same (I've printed the reference) but the stack call is different. I've printed it and made a diff and the only difference is:

<   at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
---
>   at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)

So it seems that one is called by line 310 and the other one is called by 312. It seems to happen when the request takes a little more time (it has to go to the database, etc).

I've tested with FF and Chrome and also this request is a GET request made via the browser bar so it doesn't have any kind of front-end code.

The application is running under Apache Tomcat/7.0.47.

Code example:

@Controller
@RequestMapping(value = "/base")
public class AdyenApiController {

    @Autowired
    private AdyenNotificationService service;

    @RequestMapping(value = "/debug/due", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity<String> dueScheduler() {
        try {
            throw new RuntimeException();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("> " + this);
        System.out.println("EXECUTING?!");
        service.processModifications();
        return new ResponseEntity<>("processed dues)", HttpStatus.OK);
    }
}

Does someone have any idea what this might be?

rpvilao
  • 1,116
  • 2
  • 14
  • 31
  • Can you paste in whole error, and your controller code? – Aeseir Nov 06 '14 at 22:49
  • There is no error I'm making the error just to see the stack. The error is the controller being called twice. – rpvilao Nov 06 '14 at 22:53
  • So to clarify you type localhost/some_page and it will call the same "method twice that is mapped to "some_page"? – Aeseir Nov 06 '14 at 22:54
  • Exactly. The thing is, the controller is always the same so I ruled out two instances of the same controller and the most strange thing is the difference between the stacks as I posted above :/ – rpvilao Nov 06 '14 at 23:40
  • can you show us your controller code at least that contains this request mapping? – Aeseir Nov 06 '14 at 23:43
  • This might help - http://stackoverflow.com/questions/4460661/what-to-do-with-chrome-sending-extra-requests – Bond - Java Bond Nov 07 '14 at 07:04
  • 1
    The controller is called twice because there are two requests. The difference between the stack traces is most likely caused by the fact that there is / was already an established connection when the second request arrives. – a better oliver Nov 07 '14 at 08:52
  • Updated the question to include the code sample. – rpvilao Nov 07 '14 at 08:59
  • You're right. After packet inspection I found out the browser was issuing two requests. It seems that chrome does it so it seems to be a "feature". – rpvilao Nov 07 '14 at 10:58

2 Answers2

0

It was Chrome making two requests.

rpvilao
  • 1,116
  • 2
  • 14
  • 31
0

yes. this occurred in Chrome, but for Safari, it's OK.

see my result, print user-agent incomming:1498879041319, agent =Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 incomming:1498879041596, agent =Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 incomming:1498879049068, agent =Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50

hugo
  • 45
  • 2