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

SurrealDbClient disconnects in WC endpoint #90

Closed
Dash83UPV opened this issue Mar 27, 2024 · 1 comment · Fixed by #91
Closed

SurrealDbClient disconnects in WC endpoint #90

Dash83UPV opened this issue Mar 27, 2024 · 1 comment · Fixed by #91

Comments

@Dash83UPV
Copy link

Dash83UPV commented Mar 27, 2024

Dear all
Thank you for your hard work.

I have found a possible issue. It seems that the SurrealDBClient doesn't maintain the connection.
I have been using the latest 0.40 version with Core NET 8.0

This is the test code I have prepared. In the SurrealDB (latest version 1.3.1) is the table tweets with only one record.

DataBaseParams dbParams = new DataBaseParams()
{
    ipAddress = "192.168.0.1",
    port = 8000,
    username = "root",
    password = "root",
    database = "testdb",
    dataBaseEngine = DataBaseEngine.SurrealDB
};

var surrealDBClient = new SurrealDbClient(
                SurrealDbOptions
                    .Create()
                    .WithEndpoint($"ws://{dbParams.ipAddress}:{dbParams.port}/rpc")
                    .WithUsername(dbParams.username)
                    .WithPassword(dbParams.password)
                    .WithNamespace(dbParams.database)
                    .WithDatabase(dbParams.database)
                    .Build(),
                null,
                (_options) =>
                {
                    _options.IncludeFields = true;
                }
);

int iCount = 0;
do
{
    Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ")} Query");
    SurrealDbResponse result = await surrealDBClient.RawQuery("SELECT * FROM tweets;");
    if (result.FirstOk != null)
    {
        Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ")} Total Results: {result.FirstOk?.GetValue<List<Tweet>>()?.Count}");
    }
    else
    {
        Console.WriteLine(result.FirstError?.ToString());
    }
    Thread.Sleep(60 * 1000);
    iCount++;
} while (iCount < 100);

This code produces the following result

2024-03-27T12:06:49Z Query
2024-03-27T12:06:50Z Total Results: 1
2024-03-27T12:07:50Z Query

... It is stuck ...
I pressed CTRL+C

And the docker compose logs are

surrealdb-surreal-1  | 2024-03-27T11:06:51.372748Z DEBUG request: surreal::net::tracer: started processing request otel.kind="server" http.request.method="GET" url.path="/rpc" network.protocol.name="http" network.protocol.version="1.1" otel.name="GET /rpc" http.route="/rpc" http.request.id="ee0e2c68-f781-4c8b-94cf-e266570c2747" client.address="172.16.200.2"
surrealdb-surreal-1  | 2024-03-27T11:06:51.372912Z DEBUG request: surreal::net::tracer: finished processing request otel.kind="server" http.request.method="GET" url.path="/rpc" network.protocol.name="http" network.protocol.version="1.1" otel.name="GET /rpc" http.route="/rpc" http.request.id="ee0e2c68-f781-4c8b-94cf-e266570c2747" client.address="172.16.200.2" http.response.body.size="0" http.response.status_code=101 http.latency.ms=0
surrealdb-surreal-1  | 2024-03-27T11:06:51.373136Z TRACE surreal::rpc::connection: WebSocket ee0e2c68-f781-4c8b-94cf-e266570c2747 connected
surrealdb-surreal-1  | 2024-03-27T11:06:51.501393Z DEBUG rpc/call: surreal::rpc::connection: Process RPC request otel.kind="server" ws.id=ee0e2c68-f781-4c8b-94cf-e266570c2747 rpc.service="surrealdb" rpc.method="use" otel.name="surrealdb.rpc/use" rpc.request_id="24c9bb56"
surrealdb-surreal-1  | 2024-03-27T11:06:51.501427Z DEBUG rpc/call: surreal::rpc::response: Process RPC response otel.kind="server" ws.id=ee0e2c68-f781-4c8b-94cf-e266570c2747 rpc.service="surrealdb" rpc.method="use" otel.name="surrealdb.rpc/use" rpc.request_id="24c9bb56"
surrealdb-surreal-1  | 2024-03-27T11:06:51.566271Z DEBUG rpc/call: surreal::rpc::connection: Process RPC request otel.kind="server" ws.id=ee0e2c68-f781-4c8b-94cf-e266570c2747 rpc.service="surrealdb" rpc.method="signin" otel.name="surrealdb.rpc/signin" rpc.request_id="5da0a4d0"
surrealdb-surreal-1  | 2024-03-27T11:06:51.607856Z TRACE rpc/call: surrealdb_core::iam::signin: Signing in as root otel.kind="server" ws.id=ee0e2c68-f781-4c8b-94cf-e266570c2747 rpc.service="surrealdb" rpc.method="signin" otel.name="surrealdb.rpc/signin" rpc.request_id="5da0a4d0"
surrealdb-surreal-1  | 2024-03-27T11:06:51.607913Z DEBUG rpc/call: surreal::rpc::response: Process RPC response otel.kind="server" ws.id=ee0e2c68-f781-4c8b-94cf-e266570c2747 rpc.service="surrealdb" rpc.method="signin" otel.name="surrealdb.rpc/signin" rpc.request_id="5da0a4d0"
surrealdb-surreal-1  | 2024-03-27T11:06:51.619769Z DEBUG rpc/call: surreal::rpc::connection: Process RPC request otel.kind="server" ws.id=ee0e2c68-f781-4c8b-94cf-e266570c2747 rpc.service="surrealdb" rpc.method="query" otel.name="surrealdb.rpc/query" rpc.request_id="1bf1a489"
surrealdb-surreal-1  | 2024-03-27T11:06:51.619912Z DEBUG rpc/call:execute:process:executor: surrealdb_core::dbs::executor: Executing: SELECT * FROM tweets otel.kind="server" ws.id=ee0e2c68-f781-4c8b-94cf-e266570c2747 rpc.service="surrealdb" rpc.method="query" otel.name="surrealdb.rpc/query" rpc.request_id="1bf1a489"
surrealdb-surreal-1  | 2024-03-27T11:06:51.620127Z TRACE rpc/call:execute:process:executor: surrealdb_core::dbs::iterator: Iterating: SELECT * FROM tweets otel.kind="server" ws.id=ee0e2c68-f781-4c8b-94cf-e266570c2747 rpc.service="surrealdb" rpc.method="query" otel.name="surrealdb.rpc/query" rpc.request_id="1bf1a489"
surrealdb-surreal-1  | 2024-03-27T11:06:52.296716Z DEBUG rpc/call: surreal::rpc::response: Process RPC response otel.kind="server" ws.id=ee0e2c68-f781-4c8b-94cf-e266570c2747 rpc.service="surrealdb" rpc.method="query" otel.name="surrealdb.rpc/query" rpc.request_id="1bf1a489"
surrealdb-surreal-1  | 2024-03-27T11:07:52.331155Z DEBUG rpc/call: surreal::rpc::connection: Process RPC request otel.kind="server" ws.id=ee0e2c68-f781-4c8b-94cf-e266570c2747 rpc.service="surrealdb" rpc.method="query" otel.name="surrealdb.rpc/query" rpc.request_id="fcd7f64"
surrealdb-surreal-1  | 2024-03-27T11:07:52.331286Z DEBUG rpc/call:execute:process:executor: surrealdb_core::dbs::executor: Executing: SELECT * FROM tweets otel.kind="server" ws.id=ee0e2c68-f781-4c8b-94cf-e266570c2747 rpc.service="surrealdb" rpc.method="query" otel.name="surrealdb.rpc/query" rpc.request_id="fcd7f64"
surrealdb-surreal-1  | 2024-03-27T11:07:52.331384Z TRACE rpc/call:execute:process:executor: surrealdb_core::dbs::iterator: Iterating: SELECT * FROM tweets otel.kind="server" ws.id=ee0e2c68-f781-4c8b-94cf-e266570c2747 rpc.service="surrealdb" rpc.method="query" otel.name="surrealdb.rpc/query" rpc.request_id="fcd7f64"
surrealdb-surreal-1  | 2024-03-27T11:07:53.036915Z DEBUG rpc/call: surreal::rpc::response: Process RPC response otel.kind="server" ws.id=ee0e2c68-f781-4c8b-94cf-e266570c2747 rpc.service="surrealdb" rpc.method="query" otel.name="surrealdb.rpc/query" rpc.request_id="fcd7f64"
surrealdb-surreal-1  | 2024-03-27T11:07:53.037459Z TRACE surreal::rpc::connection: WebSocket error: Error { inner: Protocol(ResetWithoutClosingHandshake) }
surrealdb-surreal-1  | 2024-03-27T11:07:53.037673Z TRACE surreal::rpc::connection: WebSocket ee0e2c68-f781-4c8b-94cf-e266570c2747 disconnected
surrealdb-surreal-1  | 2024-03-27T11:07:53.038084Z DEBUG request: surreal::net::tracer: started processing request otel.kind="server" http.request.method="GET" url.path="/rpc" network.protocol.name="http" network.protocol.version="1.1" otel.name="GET /rpc" http.route="/rpc" http.request.id="06cc2a07-65bd-42ea-92b8-5d31326093a3" client.address="172.16.200.2"
surrealdb-surreal-1  | 2024-03-27T11:07:53.038250Z DEBUG request: surreal::net::tracer: finished processing request otel.kind="server" http.request.method="GET" url.path="/rpc" network.protocol.name="http" network.protocol.version="1.1" otel.name="GET /rpc" http.route="/rpc" http.request.id="06cc2a07-65bd-42ea-92b8-5d31326093a3" client.address="172.16.200.2" http.response.body.size="0" http.response.status_code=101 http.latency.ms=0
surrealdb-surreal-1  | 2024-03-27T11:07:53.038505Z TRACE surreal::rpc::connection: WebSocket 06cc2a07-65bd-42ea-92b8-5d31326093a3 connected
surrealdb-surreal-1  | 2024-03-27T11:08:46.953012Z TRACE surreal::rpc::connection: WebSocket error: Error { inner: Io(Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" }) }
surrealdb-surreal-1  | 2024-03-27T11:08:46.953145Z TRACE surreal::rpc::connection: WebSocket 06cc2a07-65bd-42ea-92b8-5d31326093a3 disconnected

As seen, the first query works perfectly, but the following ones do not work or something happens with the SurreablDB and the message Iterating does not appear.

If I reduce the delay between Queries it work perfectly.
If I repeat the same experiment but with and HTTP enpoint it works perfectly.

Could you kindly take a look at it.

Bst regards.

@Odonno
Copy link
Contributor

Odonno commented Mar 27, 2024

Hello Alfonso,

I was curious that no "ping" event was sent in your logs. And it seems I inadvertedly inverted the null check for the timer in the ping handler. I made a fix for this. The ping event is sent regularly to prevent socket to be closed.

Will publish a v0.5.0 asap.

@kearfy kearfy closed this as completed in #91 Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants