framework icon indicating copy to clipboard operation
framework copied to clipboard

[Feature] Implement Configurable XHR Request Timeout in com.vaadin.client.communication.XhrConnection Vaadin 8

Open samwatts98 opened this issue 3 years ago • 1 comments

Current Issue

In Vaadin 8.11, our clients are experiencing intermittent issues where some UIDL XHR requests are taking ~5 minutes to resolve at random. Upon looking into configurable timeouts for XHR requests I found that this feature is currently a TODO in com.vaadin.client.communication.XhrConnection#send(JsonObject) in both v8.11 and v8.12:

    RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, getUri());

    addXsrfHeaderFromCookie(rb);

    // TODO enable timeout
    // rb.setTimeoutMillis(timeoutMillis);
    // TODO this should be configurable
    rb.setHeader("Content-Type", JsonConstants.JSON_CONTENT_TYPE);
    rb.setRequestData(payload.toJson());

Expected behavior

A configurable value, whether this is done as a Servlet initial parameter, or through the UI instance, to set a timeout on XHR requests from the Client-side browser -> Vaadin Webserver.

Actual behavior

XHR Requests never timeout and if the response is never received the application is completely frozen until the user hard refreshes.

samwatts98 avatar Oct 14 '20 11:10 samwatts98

Depending on your application runtime environment and requirements, you could use a workaround setting all XHR requests timeout in JavaScript:

!function(send){
    XMLHttpRequest.prototype.send = function (data) {
        this.timeout=10000;
        console.log("Using XHR timeout:"+this.timeout);
        send.call(this, data);
    }
}(XMLHttpRequest.prototype.send);

samie avatar Mar 28 '23 09:03 samie