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

ExecuteAsync Swallowing Errors #127

Open
mattKorwel opened this issue Oct 26, 2022 · 1 comment
Open

ExecuteAsync Swallowing Errors #127

mattKorwel opened this issue Oct 26, 2022 · 1 comment

Comments

@mattKorwel
Copy link

mattKorwel commented Oct 26, 2022

I'm working on using ExecuteAsync and I see in the logs that I'm getting an error, in my case a 409 conflict error, but its not coming back in any of the responses. I may be using it wrong but i think it should be telling me there is an error.

I'm running on 1.38.

In an example case the code below returns on the last line with an empty response array even though there are one or more errors on the back end that are visible in the logs.

It seems that 'gotResponse' is false and there are no responses on the response channel at all but also no errors?

        responseChannel := make(chan gremcosinterfaces.AsyncResponse, 2)

	err := c.cosmos.ExecuteAsync(query.String(), responseChannel)
	if err != nil {
		return nil, err
	}

	responses := make([]gremcosinterfaces.Response, 0)
        gotResponse := false
	for response := range responseChannel {
		if response.ErrorMessage != "" {
			return nil, fmt.Errorf(response.ErrorMessage)
		}
		if !response.Response.IsEmpty() {
			if response.Response.Status.Code >= 300 {
				return nil, fmt.Errorf("(%d) %s", response.Response.Status.Code, response.Response.Status.Message)
			}
			responses = append(responses, response.Response)
		}
                gotResponse = true
	}
        fmt.Println(gotResponse)
	return responses, nil
@jiping-s
Copy link

jiping-s commented Oct 11, 2023

We got the same problem. I tried the internal client without pooling and ExecuteAsync hangs after a few requests:

	ws, wsErr := gremcos.NewWebsocket(cfg.GraphURL, gremcos.SetWritingWait(time.Second*5), gremcos.SetReadingWait(time.Second*5), gremcos.SetBufferSize(1048576, 1048576))
	if wsErr != nil {
		logger.Fatalf("failed to create ws: %v", wsErr)
	}
	errCh := make(chan error, 1000)

	cosmos, cosmosErr := gremcos.Dial(ws, errCh, gremcos.SetAuth(gremcos.StaticCredentialProvider{
		UsernameStatic: cfg.GraphUsername,
		PasswordStatic: cfg.GraphPassword,
	}))
	if cosmosErr != nil {
		logger.Fatalf("failed to create Cosmos client: %v", cosmosErr)
	}

	for {
		if async {
			c := make(chan interfaces.AsyncResponse, 100)
			go func() {
				r := <-c
				concurrentIssue := false
				if r.ErrorMessage != "" {
					if !strings.Contains(r.ErrorMessage, "PreconditionFailedException") &&
						!strings.Contains(r.ErrorMessage, "Conflict") {
						logger.Panic(r.ErrorMessage)
					}
				}
				logger.Infof("inserted to gremlin: %s %d %v", r.Response.RequestID, r.Response.Status.Code, concurrentIssue)
			}()
			if err := cosmos.ExecuteAsync(query, c); err != nil {
				logger.Panic(err)
			}
			logger.Info("inserting")
			time.Sleep(100 * time.Millisecond)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants