Skip to content

System.err: java.net.ConnectException: Connection timed out not handled by angular NS #1326

Open
@hackerunet

Description

@hackerunet

Modules involved: import { HttpClient, HttpHeaders, HttpResponse, HttpErrorResponse } from "@angular/common/http";
TNS info:

✔ Getting NativeScript components versions information...
⚠ Update available for component nativescript. Your current version is 4.0.0 and the latest available version is 4.0.1.
✔ Component tns-core-modules has 4.0.0 version and is up to date.
✔ Component tns-android has 4.0.1 version and is up to date.
✔ Component tns-ios has 4.0.1 version and is up to date.

node version: v9.8.0
tns --version : 4.0.0

Case:
Using a simple POST request and not passing timeout parameter will return a Unknown Error, no status code no HttpErrorResponse object.

Nativescript Angular: handles the timeout using import "rxjs/add/operator/timeout"; but this just deattach the subscriber from the Observable and returns nothing, and then after java has consume the http request time android returns a System.err: java.net.ConnectException: Connection timed out but Nativescript angular is not able to determine the object type so if no timeout parameter is added from angular, angular returns a Unknown Error response which is not ok because from angular we should be able to set up timeout options that affects in fact the android / java stack so that way when android fails we can get the HttpErrorResponse object.

How to replicate:

this.http.post(url, body, { headers: headers })
            .timeout(3000).catch(this.handleTimeout)
            .map(response =>{
                return response;
            })
            .catch(this.handleErrors);
handleTimeout(error) {
        console.log(error);
        return error;
    }

In the console we got: JS: TimeoutError: Timeout has occurred which is not an HttpResponseError object.
After the error is returned wait 5 more minutes and check the console for this:

JS: TimeoutError: Timeout has occurred
System.err: java.net.ConnectException: Connection timed out
System.err:     at java.net.PlainSocketImpl.socketConnect(Native Method)
System.err:     at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:343)
System.err:     at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:205)
System.err:     at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:187)
System.err:     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
System.err:     at java.net.Socket.connect(Socket.java:586)
System.err:     at com.android.okhttp.internal.Platform.connectSocket(Platform.java:113)
System.err:     at com.android.okhttp.Connection.connectSocket(Connection.java:196)
System.err:     at com.android.okhttp.Connection.connect(Connection.java:172)
System.err:     at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
System.err:     at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257)
System.err:     at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
System.err:     at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
System.err:     at org.nativescript.widgets.Async$Http$RequestOptions.writeContent(Async.java:313)
System.err:     at org.nativescript.widgets.Async$Http$HttpRequestTask.doInBackground(Async.java:536)
System.err:     at org.nativescript.widgets.Async$Http$1.run(Async.java:482)
System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
System.err:     at org.nativescript.widgets.Async$PriorityThreadFactory$1.run(Async.java:52)
System.err:     at java.lang.Thread.run(Thread.java:761)

If no timeout handler is added angular should get the HttpResponseError object but is not, it is just returning "Unknown error".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions