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

MongoDB: fix cursor destructors #2769

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

WebFreak001
Copy link
Contributor

unsure how this hasn't triggered before - checked and fixed on MongoDB 7 now

@s-ludwig
Copy link
Member

s-ludwig commented Feb 5, 2024

Is there any test case that we can add?

@WebFreak001
Copy link
Contributor Author

I can try to create a test case for this - it didn't happen for everything, I just had this start to happen on some data and I'm not sure why. Might have been because I have really large collections where I had multiple cursors doing things

@WebFreak001
Copy link
Contributor Author

I can't manage to make a failing reproduction test case, but on my production system without this patch the program fails with:

vibe.db.mongo.connection.MongoDriverException@../.dub/packages/vibe-d-0.9.8-beta.3/vibe-d/mongodb/vibe/db/mongo/connection.d(462): command failed: Invalid namespace specified 'user_admin_todo_tbl_08D8C8DCF2B3FD74.' in vibe.db.mongo.connection.MongoConnection.killCursors (../.dub/packages/vibe-d-0.9.8-beta.3/vibe-d/mongodb/vibe/db/mongo/connection.d:636

(where user_admin_todo_tbl_08D8C8DCF2B3FD74 is my table's name)

in code:

	MongoCollection tableCollection()
	{
		return _someExistingCollection.database[name];
	}

	TableRow[] findTable()(Bson[string] query, auto ref in User user, size_t maxRows = size_t.max)
	{
		bool[] includedColumns = generateIncludedColumns(user);
		TableRow[] fields;
		auto cursor = tableCollection.find(query); // <-- caused by this destructor
		if (cursor.empty)
			return [];
		UserRowMatcher rowMatcher = getMatcher(user);
		foreach (Bson bsonRow; cursor)
		{
			...
		}
		return fields;
	}

I tried to test in a separate function:

  • empty cursor
  • 100000 inserts and then iterating over all

however both worked fine / didn't cause failure (with similar code layout as seen above).

Can we just merge this as-is since the tests don't regress from this and on my production system it fixes the actual issue?

unsure how this hasn't triggered before - checked and fixed on MongoDB 7 now
@s-ludwig s-ludwig force-pushed the mongodb-7-cursor-dtors branch from 24c7b20 to 4c96c6e Compare February 14, 2024 13:34
@s-ludwig s-ludwig enabled auto-merge February 14, 2024 13:34
@s-ludwig s-ludwig merged commit 8361a9b into vibe-d:master Feb 14, 2024
39 checks passed
@WebFreak001 WebFreak001 deleted the mongodb-7-cursor-dtors branch February 14, 2024 13:57
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.

2 participants