Coder Social home page Coder Social logo

Comments (8)

KazuhitoNakamura avatar KazuhitoNakamura commented on May 30, 2024

Hello, @jeremyforan.

Thank you for your suggestions.
I support the introduction of slog. I have experience using slog in another project, so I understand its benefits.

from appsync-client-go.

jeremyforan avatar jeremyforan commented on May 30, 2024

Hello @KazuhitoNakamura,

I will make a pull request. Also, I have made a small change for you to consider.

func (r *realtimeWebSocketOperation) readLoop() {
...
_, payload, err := r.ws.ReadMessage()
if err != nil {
	if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
		slog.Warn("connection timeout")
	} else {
		slog.ErrorContext(r.ctx, "error reading message", "error", err)
	}
	r.onConnectionLost(err)
	return
}

We were getting intermittent "connection reset by peer" message. It looks like AWS is closing the session without warning. This would happen after a day or two of a single websocket being open. Because the error was not a timeout the onConnectionLost wasn't be called.

The change will always result in r.onConnectionLost(err) on a r.ws.ReadMessage() error. What do you think? Is there other considerations to be made here?

from appsync-client-go.

KazuhitoNakamura avatar KazuhitoNakamura commented on May 30, 2024

Thank you so much for your pull request, I have confirmed the pull request.

I don't think this change will result in the expected behavior since onConnectionLost is always called when a ReadMessage error occurs and is not limited to the error we want to resolve this time.

Is it possible to know the type of error that occurred this time?

from appsync-client-go.

jeremyforan avatar jeremyforan commented on May 30, 2024

It is difficult to capture the error as it is intermittent. It can take 2-3 days to occur. Currently we have a ticket open with AWS and they have escalated this issue to the AppSync team.

I tried using the syscall.ECONNRESET error type, based on this article https://gosamples.dev/connection-reset-by-peer/ but it did not seem to capture the error in testing:

if errors.Is(err, syscall.ECONNRESET) {
            log.Print("This is connection reset by peer error")
        }

Is there a efficient way to validate the connection is still valid? That way if there is an error we can check if the connection is still valid.

_, payload, err := r.ws.ReadMessage()
if err != nil {
	if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
		slog.Warn("connection timeout")
		r.onConnectionLost(err)
		return
	} else {
		// check if connection has been lost
		slog.ErrorContext(r.ctx, "error reading message", "error", err)
		r.onConnectionLost(err)
		return
	}
		slog.Warn("error reading message", "error", err)
	return
}

from appsync-client-go.

KazuhitoNakamura avatar KazuhitoNakamura commented on May 30, 2024

I apologize for the late reply.
Iā€™m afraid, I'm not sure that way to check if connection has been lost for now.
I will read the source code to see if there are any errors that validate the connection has been broken.

To introduce slog ahead of time, could you remove this small change from the #31?

from appsync-client-go.

jeremyforan avatar jeremyforan commented on May 30, 2024

Hey @KazuhitoNakamura

I agree with you.

I will push the changes as per your comment so that we can include the slog functionality. I will push the changes shortly.

from appsync-client-go.

KazuhitoNakamura avatar KazuhitoNakamura commented on May 30, 2024

I found it quite difficult to check if the connection was lost because there are several errors defined in errors.New().

...

from appsync-client-go.

jeremyforan avatar jeremyforan commented on May 30, 2024

merge complete.

from appsync-client-go.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.