During an update with upsert:true option, two (or more) threads may attempt an upsert operation using the same query predicate and, upon not finding a match, the threads will attempt to insert a new document. Both inserts will (and should) succeed, unless the second causes a unique constraint violation. This MongoDB behavior is documented here.
It is expected that the client will take appropriate action upon detection of such constraint violation. Appropriate action may vary depending on individual application requirements.
This ticket tracks the cases where the server can automatically retry performing the upsert as an update rather than requiring the client to do so. Those scenarios are limited to cases where the violated unique constraint is an exact match to equality in the query predicate of the update operation (and no other fields being tested in the predicate). Only then could the server safely retry the upsert operation as an update/upsert.