Skip to content
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

How can I know errors like ConnectionTimeoutException in chunked query? #523

Closed
MichaelHai opened this issue Sep 25, 2018 · 2 comments
Closed
Labels
Milestone

Comments

@MichaelHai
Copy link

MichaelHai commented Sep 25, 2018

When I tried to execute a chunked query, it looks like no way to know about the query is failed because of errors like ConnectionTimeoutException. Since the chunked query is executed in an async way, my consumer cannot know about whether the query is finished or not so it can only keep waiting. Here is my code:

influxDB.query(query, chunkSize, queryResult -> {
            // Tricky solution in influxdb-java to singal the end of the stream
            // Refs: https://github.com/influxdata/influxdb-java/pull/270
            // Possible Future Improvement: https://github.com/influxdata/influxdb-java/issues/515
            try {
                if (queryResult.getError() != null) {
                    if (queryResult.getError().equals("DONE")) {
                        allFetched.finish();
                    } else {
                        errorHandler.accept(new RuntimeException(queryResult.getError()));
                    }
                } else {
                    InfluxDBResultMapper resultMapper =
                        new InfluxDBResultMapper();
                    consumer.accept(resultMapper.toPOJO(
                        queryResult,
                        consumedClass
                    ));
                }
            } catch (Exception ex) {
                errorHandler.accept(ex);
            }
        });

I haved looked into the code of influxdb-java and okhttp3. In influxdb-java, the failure callback do nothing but throw back the exception from okhttp3 like this:

            public void onFailure(Call<ResponseBody> call, Throwable t) {
                throw new InfluxDBException(t);
            }

And in okhttp3, for failure callback who also throws exception, it just print the stacktrace and finished. In this case, my consumer is not called at all and it looks no way to know about such failure in my code.

                public void onFailure(okhttp3.Call call, IOException e) {
                    this.callFailure(e);
                }

                private void callFailure(Throwable e) {
                    try {
                        callback.onFailure(OkHttpCall.this, e);
                    } catch (Throwable var3) {
                        var3.printStackTrace();
                    }

                }
rhajek added a commit to bonitoo-io/influxdb-java that referenced this issue Sep 26, 2018
rhajek added a commit to bonitoo-io/influxdb-java that referenced this issue Sep 26, 2018
rhajek added a commit to bonitoo-io/influxdb-java that referenced this issue Sep 26, 2018
rhajek added a commit to bonitoo-io/influxdb-java that referenced this issue Sep 26, 2018
@rhajek rhajek added this to the 2.14 milestone Sep 26, 2018
@rhajek
Copy link
Contributor

rhajek commented Sep 26, 2018

I think, this issue is a bug, there is no way how to handle this error.
I prepared the pull request for 2.14 that solves this by adding onFailure consumer into chunking query API. There is also possibility to cancel processing in any time and handle error without queryResult.getError().equals("DONE") hack.

influxDB.query(query, chunksize,
        //onNext result consumer
        (cancellable, queryResult) -> {
            System.out.println("Process queryResult - " + queryResult.toString());
        }
        //onComplete executable
        , () -> {
            System.out.println("On Complete - the query finished successfully.");
        },
        //onFailure error handler
        throwable -> {
            System.out.println("On Failure - " + throwable.getLocalizedMessage());
        });
    

@MichaelHai
Copy link
Author

Get it. Thank you for the fixing.

majst01 added a commit that referenced this issue Sep 28, 2018
Fixed issue #523: onError handling for chunked queries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants