Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dull-carrots-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hyperdx/api": patch
---

Disable mongoose autoIndex in check-alerts worker to prevent MongoExpiredSessionError
3 changes: 2 additions & 1 deletion packages/api/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mongoose.connection.on('reconnectFailed', () => {
logger.error('Failed to reconnect to MongoDB');
});

export const connectDB = async () => {
export const connectDB = async (options?: mongoose.ConnectOptions) => {
// breadcrumbs for future greppers: aws4 is included as a dependency of the api so that
// users can use AWS auth in their mongo connection string here, e.g.
// mongodb+srv://blahblah...mongodb.net/hyperdx?authSource=%24external&authMechanism=MONGODB-AWS
Expand All @@ -61,6 +61,7 @@ export const connectDB = async () => {
await mongoose.connect(config.MONGO_URI, {
heartbeatFrequencyMS: 10000, // retry failed heartbeats
maxPoolSize: 100, // 5 nodes -> max 1000 connections
...options,
});
};

Expand Down
7 changes: 6 additions & 1 deletion packages/api/src/tasks/checkAlerts/providers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ async function loadAlert(

export default class DefaultAlertProvider implements AlertProvider {
async init() {
await Promise.all([connectDB()]);
// The check-alerts worker only reads from MongoDB and never needs to
// ensure indexes exist (the API service owns that). Disabling autoIndex
// prevents background createIndexes calls from racing the short-lived
// connection close (which sends endSessions), surfaced as
// MongoExpiredSessionError on mongodb.createIndexes spans.
await Promise.all([connectDB({ autoIndex: false })]);
}

async asyncDispose() {
Expand Down
Loading