Skip to content

Validator keeps validating even though there is no client waiting for the result #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jakubklimek opened this issue Apr 24, 2019 · 3 comments

Comments

@jakubklimek
Copy link

I used the web service for validation or larger files (https://mvcr1.opendata.cz/czechpoint/2008.json, https://mvcr1.opendata.cz/czechpoint/2007.json, ...)

The web service is run behind a reverse-proxy, which has a timeout set. When the POST request timed out, the validator kept on running even though the connection was already terminated. This needs to be detected and the validation needs to be stopped when there is no longer any client waiting for the results.

@malyvoj3
Copy link
Owner

Do you know how to detect it? It is HTTP communication, which is stateless. So I cannot detect that client abort the request. Only solution how to check that client is still waiting is this

private boolean isConnected(HttpServletResponse servletResponse) {
        try {
            servletResponse.getOutputStream().print("a");
            servletResponse.flushBuffer();
            return true;
        } catch (IOException e) {
            return false;
        }
 }

but this will write to output and it can't be deleted.
I think the only possible solution is to add HTTP header Keep-alive to the request, with maximum timeout and after reaching the timeout, validation will be stopped.

@jakubklimek
Copy link
Author

I think this would have to be detected on TCP level somehow - the TCP connection is open until the response is received. When the timeout happens (or the user clicks a Stop button, closes browser, etc.) the connection is closed. This should be detectable, even though I do not know the specifics.

@malyvoj3
Copy link
Owner

malyvoj3 commented Apr 25, 2019

Yes on TCP level it should be detectable, but you can't get to TCP level with Java Web services. If there should be some stop function, which stops validating and not just the waiting for the response, then whole communication should be asynchronous - send file to validating, return id of validation and then client will ask server if it is done. But this will required database, so the validator will be big web application and not a Java library as it is said in thesis assignment.

However I will implemented it now with code I've sended in the previous comment. I realized, that I can print to outputStream spaces, which don't break JSON format. And if connection is closed, outputStream will throw the IOException and then I can stop validating. This solution is working with REST web service but not with Vaadin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants