discord-jda / JDA

Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Apache License 2.0
4.26k stars 730 forks source link

Exception in WS read thread: RSV1 bit of a frame is set unexpectedly #2663

Closed freya022 closed 2 months ago

freya022 commented 4 months ago

General Troubleshooting

Version of JDA

5.0.0-beta.18

Expected Behaviour

Handle the frame gracefully I guess?

Code Example for Reproduction Steps

N/A

Code for JDABuilder or DefaultShardManagerBuilder used

JDABuilder.createLight(token)
            .enableIntents(GatewayIntent.MESSAGE_CONTENT)
            .setActivity(Activity.customStatus("I need more bullets"))
            .setEventManager(/* */)
            .build()

Exception or Error

08:23:31.148 JDA MainWS-ReadThread      n.d.j.i.requests.WebSocketClient     #onError                  L1113  WebSocketClient      ERROR  There was an error in the WebSocket connection
com.neovisionaries.ws.client.WebSocketException: The RSV1 bit of a frame is set unexpectedly.
    at com.neovisionaries.ws.client.ReadingThread.verifyReservedBit1(ReadingThread.java:481)
    at com.neovisionaries.ws.client.ReadingThread.verifyReservedBits(ReadingThread.java:451)
    at com.neovisionaries.ws.client.ReadingThread.verifyFrame(ReadingThread.java:421)
    at com.neovisionaries.ws.client.ReadingThread.readFrame(ReadingThread.java:341)
    at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:99)
    at com.neovisionaries.ws.client.ReadingThread.runMain(ReadingThread.java:64)
    at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)

BEFORE REPORTING A SIMILAR ERROR

Please update to the JDA snapshot https://github.com/discord-jda/JDA/issues/2663#issuecomment-2091841521 and include the WebSocket trace with the error

MinnDevelopment commented 4 months ago

The latest master commit added a new trace information to further investigate this issue, please let me know when you encounter the error including that trace detail.

JayMaro commented 4 months ago

I tried this and it works fine in my environment I used JDK 17 and dependencies {implementation("net.dv8tion:JDA:5.0.0-beta.18")} and run by InteliJ This is my test code and result

import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.requests.GatewayIntent;

public class BotApplication {

    public static void main(String[] args) {
        JDABuilder.createLight(Bot.token) // my test token
            .enableIntents(GatewayIntent.MESSAGE_CONTENT)
            .setActivity(Activity.customStatus("I need more bullets"))
            .setEventManager(null)
            .build();
    }
}

스크린샷 2024-04-24 오후 9 35 32

스크린샷 2024-04-24 오후 9 35 21

freya022 commented 4 months ago

This is not an issue on startup, it happens at random times, days after the bot started, multiple people have reported this issue, I've created this issue for tracking purpose, so it can also be linked when a fix is available

JayMaro commented 4 months ago

Oh, I see. I didn't know that. Thank you for telling me. :)

duncte123 commented 4 months ago

Got one running main: https://duncte123.sentry.io/share/issue/fac5e12d2d2c40bc8baa0a46f21fc64f/

rakosi2 commented 3 months ago

Got one running 5.0.0-beta.23

freya022 commented 3 months ago

Got one running 5.0.0-beta.23

Please send the exception with the WS trace, like duncte123 sent

rakosi2 commented 3 months ago

I don't think I have WS trace enabled or how to retrieve it. I have the stacktrace that is the same as the OP [2024/05/02 23:20:23] [ERROR] [JDA MainWS-ReadThread] ERROR WebSocketClient - There was an error in the WebSocket connection com.neovisionaries.ws.client.WebSocketException: The RSV1 bit of a frame is set unexpectedly. at com.neovisionaries.ws.client.ReadingThread.verifyReservedBit1(ReadingThread.java:481) at com.neovisionaries.ws.client.ReadingThread.verifyReservedBits(ReadingThread.java:451) at com.neovisionaries.ws.client.ReadingThread.verifyFrame(ReadingThread.java:421) at com.neovisionaries.ws.client.ReadingThread.readFrame(ReadingThread.java:341) at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:99) at com.neovisionaries.ws.client.ReadingThread.runMain(ReadingThread.java:64) at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45) [2024/05/02 23:20:23] [ERROR] Exception while handling JDA event:: com.neovisionaries.ws.client.WebSocketException: The RSV1 bit of a frame is set unexpectedly. at com.neovisionaries.ws.client.ReadingThread.verifyReservedBit1(ReadingThread.java:481) at com.neovisionaries.ws.client.ReadingThread.verifyReservedBits(ReadingThread.java:451) at com.neovisionaries.ws.client.ReadingThread.verifyFrame(ReadingThread.java:421) at com.neovisionaries.ws.client.ReadingThread.readFrame(ReadingThread.java:341) at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:99) at com.neovisionaries.ws.client.ReadingThread.runMain(ReadingThread.java:64) at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)

freya022 commented 3 months ago

Ah yea, please updated to the latest snapshot:

Maven:

<repositories>
    <repository>
        <id>jitpack</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>io.github.discord-jda</groupId>
        <artifactId>JDA</artifactId>
        <version>6f7189f91a</version>
    </dependency>
</dependencies>

Gradle (Kotlin):

repositories {
    mavenCentral()
    maven("https://jitpack.io")
}

dependencies {
    implementation("io.github.discord-jda:JDA:6f7189f91a")
}
rakosi2 commented 3 months ago

I have updated my POM, will see if I get it again. https://github.com/Slaynash/Lumbot/commit/d30becdef1d36d21bbf3d425a7fd18ba68fb8ed5

MinnDevelopment commented 3 months ago

This issue has been escalated to cloudflare. Apparently, the web socket is receiving an http response body instead of a web socket frame. The specific bit happens to be set when the frame starts with HTTP/1.1 502 Bad Gateway Server.

MinnDevelopment commented 2 months ago

This should be fixed as of last Friday.