Setting custom value of maxAwaitTimeMS for change streams in sharded replica set does not seem to take effect

Hi there, I need to set custom value of maxAwaitTimeMS for change streams. I use golang mongo driver and SetMaxAwaitTime() for it. It works well on my local environment (single node). Following logs are visible in expected intervals and maxTimeMS is set to the desired value:

{"t":{"$date":"2025-04-04T08:45:17.153+00:00"},"s":"I",  "c":"COMMAND",  "id":51803,   "ctx":"conn23","msg":"Slow query","attr":{"type":"command","ns":"mydb.my_collection","appName":"myService","command":{"getMore":182525796321265817,"collection":"my_collection","maxTimeMS":60000,"lsid":{"id":{"$uuid":"4f1b938f-5b4e-492e-b392-d4ac3aaefd16"}},"$clusterTime":{"clusterTime":{"$timestamp":{"t":1743756256,"i":1}},"signature":{"hash":{"$binary":{"base64":"AAAAAAAAAAAAAAAAAAAAAAAAAAA=","subType":"0"}},"keyId":0}},"$db":"mydb"},"originatingCommand":{"aggregate":"my_collection","pipeline":[{"$changeStream":{}},{"$match":{"operationType":"update","updateDescription.updatedFields.active":true}}],"cursor":{},"lsid":{"id":{"$uuid":"4f1b938f-5b4e-492e-b392-d4ac3aaefd16"}},"$clusterTime":{"clusterTime":{"$timestamp":{"t":1743756136,"i":1}},"signature":{"hash":{"$binary":{"base64":"AAAAAAAAAAAAAAAAAAAAAAAAAAA=","subType":"0"}},"keyId":0}},"maxTimeMS":1000,"$db":"mydb","$readPreference":{"mode":"secondaryPreferred"}},"planSummary":"COLLSCAN","cursorid":182525796321265817,"keysExamined":0,"docsExamined":6,"nBatches":1,"numYields":7,"nreturned":0,"queryHash":"A4F66EB9","planCacheKey":"DEB2C5BA","queryFramework":"classic","reslen":303,"locks":{"FeatureCompatibilityVersion":{"acquireCount":{"r":8}},"Global":{"acquireCount":{"r":8}}},"readConcern":{"level":"majority"},"writeConcern":{"w":"majority","wtimeout":0,"provenance":"implicitDefault"},"storage":{},"cpuNanos":943972,"remote":"172.18.0.1:54698","protocol":"op_msg","durationMillis":0}}

When I launch my app on sharded replica set enviroment setting maxAwaitTimeMS seems not working. I see logs from a shard node in 1s interval no matter what value has been set to maxAwaitTimeMS. Am I setting this incorrectly? Is there any other way to configure it?

@Konrad_P What value are you using for maxAwaitTimeMS? From the logs it appears to be 60000ms. Do you have a reproduction case? Note that the default value for maxTimeMS on tailable cursors is 1000ms:

If no value is provided [to the getMore command], the wait time defaults to 1 (1000 milliseconds).

Same value has been provided on sharded replica set environment (60s) and following log appear each second

{"t":{"$date":"2025-04-17T14:45:26.743+00:00"},"s":"I","c":"COMMAND","id":51803,"ctx":"conn470215","msg":"Slow query","attr":{"type":"command","ns":"mydb.my_collection","appName":"myService","command":{"getMore":2470820214544151600,"collection":"my_collection","maxTimeMS":1000,"lsid":{"id":{"$uuid":"08760de4-5d87-4371-8b38-06ed05ff60bf"},"uid":{"$binary":{"base64":"eyJteU90aGVyS2V5MiI6Im15T3RoZXJWYWx1ZSJ9Cg==","subType":"0"}}},"$clusterTime":{"clusterTime":{"$timestamp":{"t":1744901125,"i":26}},"signature":{"hash":{"$binary":{"base64":"eyJteUtleSI6Im15VmFsdWUifQo=","subType":"0"}},"keyId":7436802629700682000}},"$configTime":{"$timestamp":{"t":1744901125,"i":1}},"$topologyTime":{"$timestamp":{"t":1723467667,"i":2}},"$client":{"application":{"name":"myService"},"driver":{"name":"mongo-go-driver","version":"1.17.3"},"os":{"type":"linux","architecture":"amd64"},"platform":"go1.24.2","env":{"container":{"orchestrator":"kubernetes"}},"mongos":{"host":"mongodb-sharded-mongos-1:27017","client":"192.168.203.188:34356","version":"6.0.13"}},"mayBypassWriteBlocking":false,"$db":"mydb"},"originatingCommand":{"aggregate":"my_collection","pipeline":[{"$_internalChangeStreamOplogMatch":{"filter":{"$and":[{"ts":{"$gte":{"$timestamp":{"t":1744901111,"i":17}}}},{"fromMigrate":{"$not":{"$eq":true}}},{"$or":[{"$and":[{"$or":[{"$and":[{"ns":{"$regex":"^mydb\\.my_collection$"}},{"$nor":[{"op":{"$eq":"n"}},{"op":{"$eq":"c"}}]}]},{"$and":[{"$or":[{"o.drop":{"$regex":"^my_collection$"}},{"o.renameCollection":{"$regex":"^mydb\\.my_collection$"}},{"$and":[{"o.to":{"$regex":"^mydb\\.my_collection$"}},{"o.renameCollection":{"$exists":true}}]},{"o.create":{"$regex":"^my_collection$"}},{"o.createIndexes":{"$regex":"^my_collection$"}},{"o.commitIndexBuild":{"$regex":"^my_collection$"}},{"o.dropIndexes":{"$regex":"^my_collection$"}},{"o.collMod":{"$regex":"^my_collection$"}}]},{"op":{"$eq":"c"}},{"ns":{"$regex":"^mydb\\.\\$cmd$"}}]}]},{"$or":[{"op":{"$in":["d","i"]}},{"$or":[{"$and":[{"op":{"$eq":"c"}},{"o.drop":{"$exists":true}}]},{"$and":[{"op":{"$eq":"c"}},{"o.dropDatabase":{"$exists":true}}]},{"$and":[{"op":{"$eq":"c"}},{"o.renameCollection":{"$exists":true}}]},{"$and":[{"op":{"$eq":"u"}},{"o._id":{"$exists":true}}]},{"$and":[{"op":{"$eq":"u"}},{"o._id":{"$not":{"$exists":true}}}]}]}]},{"op":{"$eq":"u"}},{"o._id":{"$not":{"$exists":true}}},{"op":{"$eq":"u"}},{"o._id":{"$not":{"$exists":true}}},{"$or":[{"o.diff.i.active":{"$eq":true}},{"o.diff.u.active":{"$eq":true}},{"o.$set.active":{"$eq":true}}]}]},{"$and":[{"$or":[{"$and":[{"o.to":{"$eq":"mydb.my_collection"}},{"o.renameCollection":{"$exists":true}}]},{"o.drop":{"$eq":"my_collection"}},{"o.renameCollection":{"$eq":"mydb.my_collection"}}]},{"ns":{"$eq":"mydb.$cmd"}},{"op":{"$eq":"c"}}]},{"$and":[{"$or":[{"o2.shardCollection":{"$exists":true}},{"o2.type":{"$in":["migrateChunkToNewShard","reshardBegin","reshardDoneCatchUp"]}}]},{"op":{"$eq":"n"}},{"ns":{"$regex":"^mydb\\.my_collection$"}}]},{"$and":[{"$or":[{"o.applyOps":{"$elemMatch":{"$and":[{"$or":[{"o.create":{"$regex":"^my_collection$"}},{"o.createIndexes":{"$regex":"^my_collection$"}}]},{"ns":{"$regex":"^mydb\\.\\$cmd$"}}]}}},{"o.applyOps.ns":{"$regex":"^mydb\\.my_collection$"}},{"prevOpTime":{"$not":{"$eq":{"ts":{"$timestamp":{"t":0,"i":0}},"t":-1}}}}]},{"op":{"$eq":"c"}},{"lsid":{"$exists":true}},{"txnNumber":{"$exists":true}},{"o.partialTxn":{"$not":{"$eq":true}}},{"o.prepare":{"$not":{"$eq":true}}},{"o.applyOps":{"$type":[4]}}]},{"$and":[{"o.commitTransaction":{"$eq":1}},{"op":{"$eq":"c"}}]}]}]}}},{"$_internalChangeStreamUnwindTransaction":{"filter":{"$and":[{"$or":[{"$and":[{"ns":{"$regex":"^mydb\\.my_collection$"}},{"$nor":[{"op":{"$eq":"n"}},{"op":{"$eq":"c"}}]}]},{"$and":[{"$or":[{"o.drop":{"$regex":"^my_collection$"}},{"o.renameCollection":{"$regex":"^mydb\\.my_collection$"}},{"$and":[{"o.to":{"$regex":"^mydb\\.my_collection$"}},{"o.renameCollection":{"$exists":true}}]},{"o.create":{"$regex":"^my_collection$"}},{"o.createIndexes":{"$regex":"^my_collection$"}},{"o.commitIndexBuild":{"$regex":"^my_collection$"}},{"o.dropIndexes":{"$regex":"^my_collection$"}},{"o.collMod":{"$regex":"^my_collection$"}}]},{"op":{"$eq":"c"}},{"ns":{"$regex":"^mydb\\.\\$cmd$"}}]}]},{"fromMigrate":{"$not":{"$eq":true}}},{"$or":[{"op":{"$in":["d","i"]}},{"$or":[{"$and":[{"op":{"$eq":"c"}},{"o.drop":{"$exists":true}}]},{"$and":[{"op":{"$eq":"c"}},{"o.dropDatabase":{"$exists":true}}]},{"$and":[{"op":{"$eq":"c"}},{"o.renameCollection":{"$exists":true}}]},{"$and":[{"op":{"$eq":"u"}},{"o._id":{"$exists":true}}]},{"$and":[{"op":{"$eq":"u"}},{"o._id":{"$not":{"$exists":true}}}]}]}]},{"op":{"$eq":"u"}},{"o._id":{"$not":{"$exists":true}}},{"op":{"$eq":"u"}},{"o._id":{"$not":{"$exists":true}}},{"$or":[{"o.diff.i.active":{"$eq":true}},{"o.diff.u.active":{"$eq":true}},{"o.$set.active":{"$eq":true}}]}]}}},{"$_internalChangeStreamTransform":{"startAtOperationTime":{"$timestamp":{"t":1744901111,"i":17}},"fullDocument":"default","fullDocumentBeforeChange":"off"}},{"$_internalChangeStreamCheckInvalidate":{}},{"$_internalChangeStreamCheckResumability":{"resumeToken":{"_data":"82680113F7000000112B0229296E04"}}},{"$_internalChangeStreamCheckTopologyChange":{}},{"$match":{"$and":[{"operationType":{"$in":["delete","drop","dropDatabase","insert","invalidate","kNewShardDetected","rename","replace","reshardBegin","reshardDoneCatchUp","update"]}},{"operationType":"update"},{"updateDescription.updatedFields.active":true}]}}],"cursor":{"batchSize":0},"maxTimeMS":60000,"needsMerge":true,"let":{"NOW":{"$date":"2025-04-17T14:45:11.691Z"},"CLUSTER_TIME":{"$timestamp":{"t":1744901111,"i":16}}},"fromMongos":true,"collation":{"locale":"simple"},"$_generateV2ResumeTokens":false,"readConcern":{"level":"local","provenance":"implicitDefault"},"writeConcern":{"w":"majority","wtimeout":0,"provenance":"customDefault"},"clientOperationKey":{"$uuid":"d3ffea72-4bb0-4755-a67c-a9554ffe61ef"},"lsid":{"id":{"$uuid":"08760de4-5d87-4371-8b38-06ed05ff60bf"},"uid":{"$binary":{"base64":"eyJteU90aGVyS2V5MiI6Im15T3RoZXJWYWx1ZSJ9Cg==","subType":"0"}}},"maxTimeMSOpOnly":60006,"$readPreference":{"mode":"secondaryPreferred"},"$clusterTime":{"clusterTime":{"$timestamp":{"t":1744901111,"i":16}},"signature":{"hash":{"$binary":{"base64":"eyJteUtleSI6Im15VmFsdWUifQo=","subType":"0"}},"keyId":7436802629700682000}},"$configTime":{"$timestamp":{"t":1744901110,"i":1}},"$topologyTime":{"$timestamp":{"t":1723467667,"i":2}},"$client":{"application":{"name":"myService"},"driver":{"name":"mongo-go-driver","version":"1.17.3"},"os":{"type":"linux","architecture":"amd64"},"platform":"go1.24.2","env":{"container":{"orchestrator":"kubernetes"}},"mongos":{"host":"mongodb-sharded-mongos-1:27017","client":"192.168.27.89:34489","version":"6.0.13"}},"mayBypassWriteBlocking":false,"$db":"mydb"},"planSummary":"COLLSCAN","cursorid":2470820214544151600,"keysExamined":0,"docsExamined":164,"numYields":361,"nreturned":0,"queryHash":"649076B3","reslen":374,"locks":{"FeatureCompatibilityVersion":{"acquireCount":{"r":362}},"Global":{"acquireCount":{"r":362}},"Mutex":{"acquireCount":{"r":1}}},"readConcern":{"level":"majority"},"writeConcern":{"w":"majority","wtimeout":0,"provenance":"customDefault"},"storage":{},"remote":"192.168.13.24:52147","protocol":"op_msg","durationMillis":6}}

as opposed to my local environment where it is 60s (value of maxAwaitTime)