Kodehawa / imageboard-api

Simple asynchronous Java API wrapper around the most popular danbooru-compatible (Konachan, Yande.re, Danbooru, Gelbooru, etc) booru APIs.
Apache License 2.0
53 stars 10 forks source link

OkHTTP Timeout #24

Closed ShindouMihou closed 3 years ago

ShindouMihou commented 3 years ago

caused by: java.net.sockettimeoutexception: timeout at okhttp3.internal.http2.http2stream$streamtimeout.newtimeoutexception(http2stream.kt:677) ~[paradoxium.jar:?] at okhttp3.internal.http2.http2stream$streamtimeout.exitandthrowiftimedout(http2stream.kt:686) ~[paradoxium.jar:?] at okhttp3.internal.http2.http2stream.takeheaders(http2stream.kt:143) ~[paradoxium.jar:?] at okhttp3.internal.http2.http2exchangecodec.readresponseheaders(http2exchangecodec.kt:96) ~[paradoxium.jar:?] at okhttp3.internal.connection.exchange.readresponseheaders(exchange.kt:106) ~[paradoxium.jar:?] at okhttp3.internal.http.callserverinterceptor.intercept(callserverinterceptor.kt:79) ~[paradoxium.jar:?] at okhttp3.internal.http.realinterceptorchain.proceed(realinterceptorchain.kt:109) ~[paradoxium.jar:?] at okhttp3.internal.connection.connectinterceptor.intercept(connectinterceptor.kt:34) ~[paradoxium.jar:?] at okhttp3.internal.http.realinterceptorchain.proceed(realinterceptorchain.kt:109) ~[paradoxium.jar:?] at okhttp3.internal.cache.cacheinterceptor.intercept(cacheinterceptor.kt:95) ~[paradoxium.jar:?] at okhttp3.internal.http.realinterceptorchain.proceed(realinterceptorchain.kt:109) ~[paradoxium.jar:?] at okhttp3.internal.http.bridgeinterceptor.intercept(bridgeinterceptor.kt:83) ~[paradoxium.jar:?] at okhttp3.internal.http.realinterceptorchain.proceed(realinterceptorchain.kt:109) ~[paradoxium.jar:?] at okhttp3.internal.http.retryandfollowupinterceptor.intercept(retryandfollowupinterceptor.kt:76) ~[paradoxium.jar:?] at okhttp3.internal.http.realinterceptorchain.proceed(realinterceptorchain.kt:109) ~[paradoxium.jar:?] at okhttp3.internal.connection.realcall.getresponsewithinterceptorchain$okhttp(realcall.kt:201) ~[paradoxium.jar:?] at okhttp3.internal.connection.realcall$asynccall.run(realcall.kt:517) [paradoxium.jar:?]

There seems to be an issue with this, though it could be because of my code. Here's a snippet of the send() part of my code.

private void send(Server server, TextChannel textChannel) {

 DefaultImageBoards.SAFEBOORU.search(rand.nextInt(35708), 50, "1girl").submit().whenComplete((p, throwable) -> {
                    List<SafebooruImage> image = GreatFilter.filter(p).stream().filter(safebooruImage -> !(GreatFilter.containsCustomExcludedTags(safebooruImage.getTags(), waifuFilter))).collect(Collectors.toList());

                    if (throwable == null) { // Checks if throwable is null.
                        if (!image.isEmpty()) {
                            MessageAPI.image(p.get(rand.nextInt(p.size() - 1)).getURL()).send(textChannel); // Sends the message containing the image.
                        } else {
                            send(server, textChannel); // Repeating the entire thing because the list is empty (don't know if this is a good thing), I could simply just redirect to Reddit source if this is bad though.
                        }
                    } else { // If throwable isn't null then redirect to Reddit source in an attempt to save.
                        reddit(server, textChannel);
                    }
                }).exceptionally(ExceptionLogger.get());
        }

I also don't know if this is an issue with the API but none of the methods I use except for the API uses OkHTTP. Extra Details:

Kodehawa commented 3 years ago

Did you try with another API (say, rule34). The implementation of the HTTP stuff is abstract and all imageboards use the same impl. If one fails but the other doesn't, it could be either your hosting, somewhere in-between (try a MTR to safebooru.org?), or something else.

ShindouMihou commented 3 years ago

Hmm, that could be an issue as the task is a timely task and I have no way of monitoring when it occurs again, though I can tell you one thing, that the command version of it seems to work just fine even after multiple uses on several servers at the same time. I will try doing something like you said on another project and see, but as you said, it could be something with my hosting.

As of now, it seems to have worked once more, and have successfully sent the image to other servers, I will get back here if this error persists though (with the suggestion).

Kodehawa commented 3 years ago

Ah. If it happens sometimes it's ok.

APIs known to give weird/meme responses, randomly:

Also just called "quirks"

ShindouMihou commented 3 years ago

Must be one of those then, I'll try handling it on my side by redirecting the fails to a Reddit source for now; thanks for the help, though. Do you want me to close the issue for now?

Kodehawa commented 3 years ago

It's ok to keep it open if it always happens. If it's a hiccup I'd put it on their side.

I should add an option to set a custom timeout, though.

ShindouMihou commented 3 years ago

I would love something like a custom timeout though.

Kodehawa commented 3 years ago

Okie. I'll add such in next release.