surrealdb/surrealdb.go

Bug: The session has expired error when connecting to version 1.3.0

Closed this issue · 4 comments

Describe the bug

version 1.3.0 has websocket session expire feature, and throw The session has expired error.

Are we supposed to handle this on our own, or this should be handled by driver?

Steps to reproduce

make connection, idle for a while, then make a request

Expected behaviour

no error, and request go through, result successfully returned

SurrealDB version

surreal 1.3.0

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

I handled this in my own code

@agufagit how did you handle it? am also facing the same issue

@agufagit how did you handle it? am also facing the same issue

if error not nil and error message contains "session has expired", close connection, call the function again to get new connection from pool

below is exact part of code where I handle this error, Query(c, query, parameters) is the function that contains this code

resultRaw, err := conn.Query(query, parameters)
if err != nil {
    if strings.Contains(err.Error(), "session has expired") {
	    println("1. db session expired")
	    errCloseConn := conn.CloseWithNew()
	    if errCloseConn != nil {
		    return nil, errors.Wrap(defaultErrors.Join(err, errCloseConn), "The session has expired, error closing db connection")
	    }
	    return Query(c, query, parameters)
    }
    callback(false)
    
    return nil, err
}

ok nice implemented it, ty also just noticed the bug has been fixed in version 1.3.1