Skip to content

Conversation

@FGasper
Copy link
Collaborator

@FGasper FGasper commented Dec 6, 2024

This fixes hangs from the change stream and document reader when contexts are canceled.

StartChangeEventHandler doesn’t need to send to the error channel. It now just returns its error.

The other channels—writes-off, error, and done—now allow infinite (non-blocking) reads once populated. This works via a new struct, Eventual, that supplies the same semantics as Context’s Done() and Err() methods. The change stream struct’s writes-off and error channels are written to be Eventual. The doneChan remains a channel but now is just closed rather than written to.

This also refactors a couple functions for general reuse and fixes TestStartAtTimeNoChanges, which has flapped occasionally.

@FGasper FGasper requested a review from tdq45gj December 6, 2024 21:20
Copy link
Collaborator

@tdq45gj tdq45gj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me in general. I wonder if there's any point calling Get before Eventual is ready.


// Get returns an option that contains the Eventual’s value, or
// empty if the value isn’t ready yet.
func (e *Eventual[T]) Get() option.Option[T] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any case that we want to call Get before it's ready? Looks like we're calling Get().MustGet() everywhere, can we make Get return T or fail if it's not ready?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that. I was/am a bit averse to proliferating panics, but you’re right that there’s little point in calling Get() before the value is ready. (It can be checked anyway by doing a select on Ready() with a default.)

I’ll change it.

sess, err := suite.srcMongoClient.StartSession()
suite.Require().NoError(err)
sctx := mongo.NewSessionContext(ctx, sess)
_, err = suite.srcMongoClient.Database("testDb").Collection("testColl").InsertOne(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use suite.DBNameForTest()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@FGasper FGasper requested a review from tdq45gj December 9, 2024 16:34
Copy link
Collaborator

@tdq45gj tdq45gj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@FGasper FGasper merged commit dd2478c into main Dec 9, 2024
98 checks passed
@FGasper FGasper deleted the REP-5358-retry-and-channels branch December 9, 2024 18:38
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 this pull request may close these issues.

3 participants