<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 04:22:00 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[SERVER-29861] Insert should report number of docs inserted or writeConcernError on error code 11602 (InterruptedDueToReplStateChange)</title>
                <link>https://jira.mongodb.org/browse/SERVER-29861</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;According to the docs and my understanding of relevant things (e.g. write concerns), I take the following to be true:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Insert should always return the number of documents inserted (&quot;n&quot;) that satisfied the write concern.&lt;/em&gt; (Where &quot;always&quot; implies that the original MongoDB server is still alive and reachable. If the server or network or etc. dies, then of course there&apos;s nothing left to report &quot;n&quot;.)&lt;/p&gt;

&lt;p&gt;This should hold true especially when the repl set state changes because this is a common and useful event. Apps should expect the primary to go away, but they should also be guaranteed that MongoDB will cleanly terminate pending ops wrt the write concern (total server/network/etc. failure notwithstanding).&lt;/p&gt;

&lt;p&gt;If the aforementioned is &lt;em&gt;not&lt;/em&gt; true, then perhaps there&apos;s no bug and &lt;a href=&quot;https://docs.mongodb.com/manual/reference/command/insert/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.mongodb.com/manual/reference/command/insert/&lt;/a&gt; just needs to be updated to reflect the real guarantees and return values. But presuming it&apos;s true, I put it to the test and found a problem: insert &lt;em&gt;sometimes&lt;/em&gt; does not return the number of docs inserted (or a writeConcernError) on error code 11602 (InterruptedDueToReplStateChange).&lt;/p&gt;

&lt;p&gt;Setup:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;MongoDB 3.4.4&lt;/li&gt;
	&lt;li&gt;3-node repl set on my laptop&lt;/li&gt;
	&lt;li&gt;journaling filesystem (Mac HFS)&lt;/li&gt;
	&lt;li&gt;mgo driver @3f83fa&lt;/li&gt;
	&lt;li&gt;write concern: &lt;tt&gt;w:2, j:true&lt;/tt&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Experiment:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;Insert array of 100,000 docs (internally: array of 1,000 docs at a time)&lt;/li&gt;
	&lt;li&gt;While the insert is happening, run &lt;tt&gt;rs.stepDown(10,5)&lt;/tt&gt; on the primary&lt;/li&gt;
	&lt;li&gt;Compare docs written (&quot;n&quot;) from mgo vs. &quot;nRemoved&quot; from &lt;tt&gt;db.docs.remove({});&lt;/tt&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Expect:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;Random number of docs written and ack&apos;ed successfully in last batch of 1,000 that&apos;s interrupted&lt;/li&gt;
	&lt;li&gt;MongoDB returns documented output &lt;a href=&quot;https://docs.mongodb.com/manual/reference/command/insert/#output&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.mongodb.com/manual/reference/command/insert/#output&lt;/a&gt; where &quot;n&quot; &amp;lt;= 1,000 for last insert that was interrupted when repl state changed&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Results:&lt;/p&gt;

&lt;p&gt;Results vary. First of all, there are 2 possible errors in the client (mgo): an EOF on the network socket (because Mongo kills connections on rs state change), or error code 11602 (InterruptedDueToReplStateChange).&lt;/p&gt;

&lt;p&gt;On EOF, there can&apos;t be any return write result (i.e. the documented output) because the connection is closed. I&apos;m not sure if this a problem in mgo (not doing a final read?) or Mongo (killing the connection before sending a final write result?) Either way, the problem arises on occasion: mgo will report N docs written, but N + some random number of docs were actually written.&lt;/p&gt;

&lt;p&gt;The 2nd error condition is my focus. Mongo seems to gracefully kill the write op, but it does not always return the documented output. First, an example of when it works:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;n&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: 1000,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;opTime&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;ts&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;$timestamp&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;t&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: 1498494120,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;i&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: 5000&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;      }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    },&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;t&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;$numberLong&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;202&quot;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  },&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;electionId&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;$oid&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;7fffffff00000000000000ca&quot;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  },&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;writeConcernError&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;code&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: 11602,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;codeName&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;InterruptedDueToReplStateChange&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;errmsg&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;operation was interrupted&quot;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  },&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;ok&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: 1&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;That&apos;s a &lt;tt&gt;bsondump&lt;/tt&gt; of the raw Go &lt;tt&gt;[]byte&lt;/tt&gt; (I hacked this into my local copy of mgo). That is what I&apos;d expect every time; it matches the documented output (plus some other, undocumented fields).&lt;/p&gt;

&lt;p&gt;But sometimes the output is only:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;ok&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: 0,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;errmsg&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;operation was interrupted&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;code&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: 11602,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;codeName&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;InterruptedDueToReplStateChange&quot;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;And in this particular case, mgo reports 14,000 docs written, but:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;rs0:PRIMARY&amp;gt; db.docs.remove({});&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;WriteResult({ &quot;nRemoved&quot; : 14320 })&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;The critical question: &lt;b&gt;is MongoDB returning a write result with n=320&lt;/b&gt;? If yes, then it&apos;s a bug in mgo. I don&apos;t think this is the case because I&apos;m writing the raw &lt;tt&gt;[]byte&lt;/tt&gt; from deep inside mgo before the data is returned up the call stack. Inside the mgo code here &lt;a href=&quot;https://github.com/go-mgo/mgo/blob/v2-unstable/socket.go#L625&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/go-mgo/mgo/blob/v2-unstable/socket.go#L625&lt;/a&gt;, I added:&lt;/p&gt;


&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;fileNo++&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;file := fmt.Sprintf(&quot;res-%d.bson&quot;, fileNo)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;ioutil.WriteFile(file, b, 0666)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;Then I &lt;tt&gt;bsondump&lt;/tt&gt; the last file written, which is the doc shown above. Furthermore, this works most of the time, but sometimes it doesn&apos;t, which leads me to believe mgo is &lt;em&gt;not&lt;/em&gt; missing a final read on the network connection; rather, Mongo is not sending a write result with &lt;tt&gt;n: 320&lt;/tt&gt; in the example above.&lt;/p&gt;

&lt;p&gt;If that&apos;s true, this is a show-stopping problem because it means an app cannot know, even with a write concern, how many docs were actually inserted. Moreover, the app might presume a wrong number (because it trusts the driver which doesn&apos;t know either), as in this case: 14,000 reported vs. 14,320 actual.&lt;/p&gt;

&lt;p&gt;&amp;#8212;&lt;/p&gt;

&lt;p&gt;Happy to provide more details, tweak my experiment, whatever. Time allowing, I&apos;ll automate the whole experiment so I can run it 1,000+ times to measure accurately the failure rate. Right now, doing it by hand, the rough estimate is 10-40% failure rate.&lt;/p&gt;</description>
                <environment></environment>
        <key id="398249">SERVER-29861</key>
            <summary>Insert should report number of docs inserted or writeConcernError on error code 11602 (InterruptedDueToReplStateChange)</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="13202">Works as Designed</resolution>
                                        <assignee username="asya.kamsky@mongodb.com">Asya Kamsky</assignee>
                                    <reporter username="dnichter">Daniel Nichter</reporter>
                        <labels>
                    </labels>
                <created>Mon, 26 Jun 2017 18:53:16 +0000</created>
                <updated>Fri, 27 Oct 2023 13:54:22 +0000</updated>
                            <resolved>Wed, 17 Jan 2018 15:21:32 +0000</resolved>
                                                                    <component>Write Ops</component>
                                        <votes>6</votes>
                                    <watches>19</watches>
                                                                                                                <comments>
                            <comment id="2225876" author="ian@10gen.com" created="Fri, 26 Apr 2019 13:32:56 +0000"  >&lt;p&gt;Switching &quot;Drivers Changes Needed&quot; from &quot;Maybe&quot; to &quot;Not Needed&quot; since this was closed as something other than Fixed.&lt;/p&gt;</comment>
                            <comment id="1776529" author="asya" created="Wed, 17 Jan 2018 15:21:32 +0000"  >&lt;p&gt;Documentation improvements will be tracked in &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-11076&quot; title=&quot;Document cases where bulk inserts may report fewer documents inserted than were actually inserted&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-11076&quot;&gt;&lt;del&gt;DOCS-11076&lt;/del&gt;&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1766830" author="dnichter" created="Sat, 6 Jan 2018 00:07:11 +0000"  >&lt;p&gt;Thanks for the in-depth discussion and exploration of this issue. You&apos;ve convinced me: it&apos;s not a bug. &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt; I think the salient point is what you said: &quot;only the number of documents that definitely were written and replicated (i.e. satisfied write concern) is returned, but more documents &lt;b&gt;may&lt;/b&gt; have been written that are not included in &quot;n&quot; because there is no proof that they were replicated before the connection was lost.&quot; I think the manual should say that because when I read this:&lt;/p&gt;

&lt;p&gt;&quot;BulkWriteResult.nInserted&lt;br/&gt;
The number of documents inserted using the Bulk.insert() method.&quot;&lt;br/&gt;
&lt;a href=&quot;https://docs.mongodb.com/manual/reference/method/BulkWriteResult/#BulkWriteResult.nInserted&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.mongodb.com/manual/reference/method/BulkWriteResult/#BulkWriteResult.nInserted&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I take that at face value. My misunderstanding would have been adverted if the docs said what you said. Then I would know: on write, I&apos;ll get &amp;gt;= n docs definitely written (wrt write concern). Then the question becomes how, from the app dev point of view, do I handle the &quot;&amp;gt;&quot; case? That depends on the app, docs, indexes, etc.&lt;/p&gt;

&lt;p&gt;Wrt the inconsistent return value on error (error code 11602): consistency is great, but inconsistency is not unusual. MySQL can report 1 of 3 different errors when the server goes away. A really well-written app will handle all three. I think with MongoDB, devs will wind up doing the same: learning all possible &quot;lost connection/server went away&quot; errors and handling all of them.&lt;/p&gt;</comment>
                            <comment id="1754849" author="asya" created="Mon, 18 Dec 2017 19:18:43 +0000"  >&lt;p&gt;It was pointed out to me that the official &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#error-handling&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;MongoDB CRUD specification document&lt;/a&gt; directs that on a write error the fields that should be returned are ones describing the error, but not &quot;n&quot; indicating how many documents were actually written, which only gets returned when there has not been an error (and an acknowledgement is requested).   &lt;/p&gt;

&lt;p&gt;This suggests that mgo driver should probably not be reporting &quot;n&quot; at all in the case of a write concern error.&lt;/p&gt;

&lt;p&gt;Linked &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-11076&quot; title=&quot;Document cases where bulk inserts may report fewer documents inserted than were actually inserted&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-11076&quot;&gt;&lt;del&gt;DOCS-11076&lt;/del&gt;&lt;/a&gt; should document how to interpret results from the driver in cases of an error.&lt;/p&gt;</comment>
                            <comment id="1748318" author="asya" created="Mon, 11 Dec 2017 14:18:57 +0000"  >&lt;blockquote&gt;&lt;p&gt;I presume the intention is for &quot;n&quot; to be correct.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;In a distributed system it is not possible to guarantee that &quot;n&quot; is correct when &quot;n&quot; depends on hearing from other parts of the system.&lt;/p&gt;

&lt;p&gt;Imagine a scenario with two nodes, where a write of a document is sent to one but must be acknowledged only when it has replicated to the second node in the system.  If the primary successfully writes the document but does not receive the acknowledgement from the second node, should it acknowledge to the client that one document was written, or zero?  One was written locally, but zero satisfied the &quot;written to both nodes&quot; request (that it knows of).   From point of view of the primary, how many documents were written on the second node?  It has no way of knowing. &lt;/p&gt;

&lt;p&gt;Since it cannot know that the document was written on the secondary, it must consider zero as the only possible correct response.  But it&apos;s possible that the document &lt;b&gt;was&lt;/b&gt; successfully written on the second node, even though knowledge of that fact never reached the primary.    &lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Insert should always return the number of documents inserted (&quot;n&quot;) that satisfied the write concern.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;is consistent with the behavior you observe - only the number of documents that definitely were written and replicated (i.e. satisfied write concern) is returned, but more documents &lt;b&gt;may&lt;/b&gt; have been written that are not included in &quot;n&quot; because there is no proof that they were replicated before the connection was lost.&lt;/p&gt;

&lt;p&gt;Note that analogous to the two node scenario is the communication between the server and the driver - if the driver does not receive acknowledgement from the server that a document was written it must not return to the application that the document was written, but nevertheless the document may have actually been written successfully.&lt;/p&gt;

&lt;p&gt;This behavior is not a bug.  &lt;/p&gt;

&lt;p&gt;There are many changes we are working on to improve the situation for the application - for example, the &lt;a href=&quot;https://docs.mongodb.com/manual/release-notes/3.6/index.html#retryable-writes&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;automatic re-try of document writes&lt;/a&gt; by the driver improves the situation for the application since it doesn&apos;t need to know how to re-try the failed write in a way that&apos;s idempotent.  (Not all drivers already support this new server feature, but that work is tracked in &lt;a href=&quot;https://jira.mongodb.org/browse/DRIVERS-396&quot; title=&quot;All writes retryable support&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DRIVERS-396&quot;&gt;&lt;del&gt;DRIVERS-396&lt;/del&gt;&lt;/a&gt;).  There may be other improvements in the server and/or in the driver(s) that could reduce the number of scenarios in which the number of successfully written documents is lower than the actual number of written documents.   But it is impossible for that scenario to be completely eliminated unless we returned no &quot;n&quot; in cases where we cannot be sure that more documents than &quot;n&quot; were successfully written.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;the other factor is that error code 11602 is sometimes sent, and sometimes not.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;It wasn&apos;t clear from the ticket whether there was potentially a server or a driver bug here.  It&apos;s probably best to investigate that in a separate ticket.&lt;/p&gt;</comment>
                            <comment id="1746461" author="dnichter" created="Fri, 8 Dec 2017 02:14:37 +0000"  >&lt;p&gt;The current behavior is not a bug? Without knowing the underlying code, I presume the intention is for &quot;n&quot; to be correct. However, if &quot;n&quot; was &lt;em&gt;not&lt;/em&gt; intended to be correct, i.e. to be only an estimate or best effort count, then I could see how it&apos;s not a bug.&lt;/p&gt;

&lt;p&gt;Also, the other factor is that  error code 11602 is sometimes sent, and sometimes not. For this, I&apos;d argue the same: if that&apos;s the original code intention, then it&apos;s not a bug (although very strange behavior for a database). But if the code intention is to always return this, then sometimes not sending it is a bug.&lt;/p&gt;</comment>
                            <comment id="1746450" author="asya" created="Fri, 8 Dec 2017 02:02:26 +0000"  >&lt;p&gt;&amp;gt; I think the real issue requires more than doc updates.&lt;/p&gt;

&lt;p&gt;Of course, that&apos;s why this is still open, but as an improvement request.&lt;/p&gt;

&lt;p&gt;One workaround is to use individual document operations rather than batch operations.&lt;/p&gt;

&lt;p&gt;Some upcoming features may also help, but they would have to be handled correctly in the driver as well as the server.&lt;/p&gt;</comment>
                            <comment id="1745850" author="dnichter" created="Thu, 7 Dec 2017 19:22:17 +0000"  >&lt;p&gt;Hello! Thanks for the reply and looking into this!&lt;/p&gt;

&lt;p&gt;I think the real issue requires more than doc updates.&lt;/p&gt;

&lt;p&gt;Imho, the goal is this: &lt;b&gt;MongoDB should &lt;em&gt;always&lt;/em&gt; report the &lt;em&gt;exact&lt;/em&gt; number of documents inserted, satisfying the write concern, under normal operation&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;Imho again, anything less than that makes the database virtually unusable because if an application cannot know, with certainty, how many docs were inserted, app development becomes very difficult. A database is often the app&apos;s source of true; it must not lie to the app wrt the data it has or hasn&apos;t stored.&lt;/p&gt;

&lt;p&gt;In the test data we see, for example, that Mongo will report 66,000 docs inserted when in reality 66,448 docs were inserted. Depending on what the app and data are used for, that could be a huge and important difference.&lt;/p&gt;

&lt;p&gt;If we accept the current behavior (doc updates notwithstanding), apps are forced not to trust the database, and they&apos;re forced to have complicated logic to verify and reconcile what the database reports (&quot;n&quot;) vs. reality. Moreover, because data is always in flight, it&apos;s not logical to presume the app can successfully reconcile the data short of taking the database offline.&lt;/p&gt;

&lt;p&gt;Re documentation for &quot;the server to provide more information about the number of documents successfully written when interrupted in the middle of a batch&quot;. There&apos;s two things here. Re &quot;middle of a batch&quot;: imho, this in an implementation detail that should not matter to the user/app. The app does not and should not care how MongoDB reliably stores a bunch of docs wrt the write concern. Second, the &quot;number of docs success written&quot; is already documented: it&apos;s &quot;n&quot;. Well, the docs say &quot;The number of documents inserted.&quot; which a user presumes to mean &quot;successfully written wrt the write concern under normal ops&quot;. Again, the user/app doesn&apos;t care about the details (under normal operation); they should simply be able to trust that if the database says N docs written, then exactly N docs have been written.&lt;/p&gt;

&lt;p&gt;I think the salient question to agree or disagree on is: &lt;em&gt;Should &quot;n&quot;, wrt write concern under normal ops, always be the exact number of docs written?&lt;/em&gt;  If &quot;no&quot;, then doc updates are in order, but (imho) such behavior seriously undermines the usability of the database because apps won&apos;t be able to trust it. If &quot;yes&quot;, then fixing this bug will be a huge win, imho. &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                            <comment id="1733913" author="asya" created="Thu, 23 Nov 2017 23:49:42 +0000"  >&lt;p&gt;The behavior you observe is due to the fact that the writeConcern is only checked at the end of every &quot;batch&quot;.&lt;/p&gt;

&lt;p&gt;This is why in the driver you see report based on multiples of 1,000 (which is the size of batches larger requests are split into).&lt;/p&gt;

&lt;p&gt;Your suggestion that documentation is implying that &lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;&quot;Insert should always return the number of documents inserted (&quot;n&quot;) that satisfied the write concern. (Where &quot;always&quot; implies that the original MongoDB server is still alive and reachable. If the server or network or etc. dies, then of course there&apos;s nothing left to report &quot;n&quot;.)&quot; &lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;suggests that documentation improvements are in order to make it more clear in what scenario the number of documents successfully acknowledged will be returned.&lt;/p&gt;

&lt;p&gt;Since this is expected behavior, I will convert this issue to an enhancement request for the server to provide more information about the number of documents successfully written when interrupted in the middle of a batch.&lt;/p&gt;</comment>
                            <comment id="1639775" author="ian@10gen.com" created="Thu, 3 Aug 2017 14:55:53 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=spencer&quot; class=&quot;user-hover&quot; rel=&quot;spencer&quot;&gt;spencer&lt;/a&gt; any thoughts from the repl team on the severity/priority of this?&lt;/p&gt;</comment>
                            <comment id="1625718" author="dnichter" created="Tue, 18 Jul 2017 21:20:49 +0000"  >&lt;p&gt;Excellent, thanks Mark! This will be a big win for app dev and ops.&lt;/p&gt;</comment>
                            <comment id="1624165" author="mark.agarunov" created="Mon, 17 Jul 2017 21:25:42 +0000"  >&lt;p&gt;Hello &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=dnichter&quot; class=&quot;user-hover&quot; rel=&quot;dnichter&quot;&gt;dnichter&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Thank you for the report and my apologies for the delay in response. I&apos;ve been able to reproduce the behavior you&apos;ve described using the detailed examples and code provided so I&apos;ve placed this ticket in &quot;Need Triage&quot; to be scheduled against our currently planned work. &lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Mark&lt;/p&gt;</comment>
                            <comment id="1613605" author="dnichter" created="Tue, 4 Jul 2017 16:54:21 +0000"  >&lt;p&gt;Re attached files: &lt;tt&gt;test1-data.csv, test1.log, test2-data.csv, test2.log&lt;/tt&gt;&lt;/p&gt;

&lt;h3&gt;&lt;a name=&quot;TL%3BDR&quot;&gt;&lt;/a&gt;TL;DR&lt;/h3&gt;

&lt;ul&gt;
	&lt;li&gt;~40% fail rate. MongoDB is definitely &lt;em&gt;not&lt;/em&gt; consistent wrt &quot;n&quot; inserted on repl state change.&lt;/li&gt;
	&lt;li&gt;Bug appears related to MongoDB sending (or mgo receiving?) error code 11602: pass when sent, fail when not sent (see below).&lt;/li&gt;
	&lt;li&gt;Test using &lt;a href=&quot;https://github.com/daniel-nichter/lab/tree/master/server-29861&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/daniel-nichter/lab/tree/master/server-29861&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;&lt;a name=&quot;Details&quot;&gt;&lt;/a&gt;Details&lt;/h3&gt;

&lt;ul&gt;
	&lt;li&gt;MongoDB 3.4.4&lt;/li&gt;
	&lt;li&gt;6 node repl set: 3 nodes on US west; 3 nodes on US east&lt;/li&gt;
	&lt;li&gt;Custom write concern called &quot;&lt;b&gt;twoack&lt;/b&gt;&quot; that requires 2 US west nodes to ack (primary + one other)&lt;/li&gt;
	&lt;li&gt;US east nodes are priority zero&lt;/li&gt;
	&lt;li&gt;Bare metal, dedicated, high-end production hardware (only MongoDB running on all 6 servers)&lt;/li&gt;
	&lt;li&gt;Using &lt;a href=&quot;https://github.com/daniel-nichter/lab/tree/master/server-29861&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/daniel-nichter/lab/tree/master/server-29861&lt;/a&gt; with command line like:&lt;/li&gt;
&lt;/ul&gt;


&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;./server-29861 -username root -password test -auth-db admin -safe-w 0 -safe-wmode twoack -tests 100 mongodb://localhost?replicaSet=rs0 1&amp;gt;data.csv 2&amp;gt;log&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;Two experiment runs with 100 tests each (1 test = the full cycle: insert, stepDown, recover, remove, count, print data).&lt;/p&gt;

&lt;h3&gt;&lt;a name=&quot;DataFields&quot;&gt;&lt;/a&gt;Data Fields&lt;/h3&gt;

&lt;p&gt;The &lt;b&gt;.csv&lt;/b&gt; files are the useful data, with fields:&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;nReported,nActual,secondsBeforeStepDown,errorString,pass&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;Where&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;nReported = the number of docs written (&quot;n&quot;) as reported by the modified, vendored-in copy of &lt;span class=&quot;error&quot;&gt;&amp;#91;mgo&amp;#93;&lt;/span&gt;(&lt;a href=&quot;http://labix.org/mgo&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://labix.org/mgo&lt;/a&gt;). You can see my mods at/btween &lt;tt&gt;@dn&lt;/tt&gt; code comments. Basically, it just makes mgo actually report &quot;n&quot; from MongoDB (which is a separate issue for mgo).&lt;/li&gt;
	&lt;li&gt;nActual = the number of docs removed as reported by MongoDB, &lt;em&gt;after&lt;/em&gt; the repl set has recovered, by doing &lt;tt&gt;db.remove()&lt;/tt&gt; on the (new) primary. This number is authoritative, how many docs are truly stored in the collection.&lt;/li&gt;
	&lt;li&gt;secondsBeforeStepDown = random wait between starting insert and doing &lt;tt&gt;rs.stopDown&lt;/tt&gt; on master, [500ms, 2).&lt;/li&gt;
	&lt;li&gt;errorString = &quot;int&quot; = &quot;operation was interrupted&quot;, &quot;eof&quot; = &quot;EOF&quot; (socket), &quot;aok&quot; = all docs inserted before secondsBeforeStepDown (rare given 250k docs are inserted)&lt;/li&gt;
	&lt;li&gt;pass = &quot;true&quot; or &quot;false&quot; depending on if nReported = nActual&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The line number of the data file = the test number (important to match results with log).&lt;/p&gt;

&lt;h3&gt;&lt;a name=&quot;Results&quot;&gt;&lt;/a&gt;Results&lt;/h3&gt;

&lt;p&gt;So the pass/fail rate is easy to calculate from the data:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;$ wc -l test1-data.csv &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;     100 test1-data.csv&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;$ grep -c true test1-data.csv &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;     62&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;100 tests and 62 pass=true = &lt;b&gt;62% pass, 38% fail&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;For test2 the results are &lt;b&gt;54% pass, 46% fail&lt;/b&gt;.&lt;/p&gt;

&lt;h3&gt;&lt;a name=&quot;Errorcode11602&quot;&gt;&lt;/a&gt;Error code 11602&lt;/h3&gt;

&lt;p&gt;I haven&apos;t checked every single &quot;pass&quot; but it seems pass=true always when Code:11602 is reported and pass=false when &lt;em&gt;not&lt;/em&gt; reported. Example: in test1, test 8, the code is reported:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:03.244208 main.go:160: test 8 of 100&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:03.244253 main.go:168: wait: 734ms&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:03.270757 main.go:276: removing&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:03.272239 main.go:197: wait&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:03.272255 main.go:256: inserting...&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:04.006344 main.go:201: rs.stepDown&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:04.006741 main.go:260: insert err: operation was interrupted (&amp;amp;mgo.LastError{Err:&quot;operation was interrupted&quot;, Code:11602, N:68000, Waited:0, FSyncFiles:0, WTimeout:false, UpdatedExisting:true, UpsertedId:interface {}(nil), modified:0, ecases:[]mgo.BulkErrorCase{}})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:20.336066 main.go:160: test 9 of 100&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:20.336103 main.go:168: wait: 779ms&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:20.362863 main.go:276: removing&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:20.363162 main.go:197: wait&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:20.363180 main.go:256: inserting...&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:21.142266 main.go:201: rs.stepDown&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;2017/07/03 17:13:21.143102 main.go:260: insert err: operation was interrupted (&amp;amp;mgo.LastError{Err:&quot;operation was interrupted&quot;, Code:0, N:66000, Waited:0, FSyncFiles:0, WTimeout:false, UpdatedExisting:false, UpsertedId:interface {}(nil), modified:0, ecases:[]mgo.BulkErrorCase{}})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;And data for 8 and 9:&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;68000,68000,0.734,int,true &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;66000,66448,0.779,int,false&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;Very similar test runs: ~66k docs and stepDown at ~0.7s, but 8 gets the error code and 9 does not. So far, this pattern holds for all the tests I&apos;ve checked.&lt;/p&gt;

&lt;h3&gt;&lt;a name=&quot;Conclusion&quot;&gt;&lt;/a&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;Root cause is unknown, but the test data proves that MongoDB is inconsistent wrt reporting the number of docs inserted (or a writeConcernError) when the replica state changes. It also proves that MongoDB doesn&apos;t report &lt;em&gt;all&lt;/em&gt; the docs inserted (e.g. 66k vs. 66,448 above). Presuming the write concern guarantees the writes (i.e. docs aren&apos;t lost during a routine repl set state change), the next must-have for production apps is reliably knowing how many docs were inserted (for an ordered insert with a write concern). Without knowing this, apps cannot easily, gracefully recover from routine repl set state changes. Lastly, only insert has been tested. Update, delete, and all other write ops should be tested, too.&lt;/p&gt;</comment>
                            <comment id="1606912" author="dnichter" created="Mon, 26 Jun 2017 19:45:13 +0000"  >&lt;p&gt;Description is correct now. Thanks Mark.&lt;/p&gt;</comment>
                            <comment id="1606840" author="dnichter" created="Mon, 26 Jun 2017 18:57:20 +0000"  >&lt;p&gt;Copy-paste error duplicated the description. It repeats at &quot;According to the docs&quot;. I can&apos;t edit it. Please delete description from start to second occurrence of &quot;According to the docs &quot;.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="465896">DOCS-11076</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="160158" name="test1-data.csv" size="2858" author="dnichter" created="Tue, 4 Jul 2017 16:50:53 +0000"/>
                            <attachment id="160157" name="test1.log" size="73653" author="dnichter" created="Tue, 4 Jul 2017 16:50:53 +0000"/>
                            <attachment id="160156" name="test2-data.csv" size="2900" author="dnichter" created="Tue, 4 Jul 2017 16:50:53 +0000"/>
                            <attachment id="160155" name="test2.log" size="73421" author="dnichter" created="Tue, 4 Jul 2017 16:50:53 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>15.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Mon, 17 Jul 2017 21:25:42 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        4 years, 41 weeks, 5 days ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>luke.bonanomi@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            4 years, 41 weeks, 5 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>asya.kamsky@mongodb.com</customfieldvalue>
            <customfieldvalue>dnichter</customfieldvalue>
            <customfieldvalue>ian@mongodb.com</customfieldvalue>
            <customfieldvalue>mark.agarunov</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|ht9xg7:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr9dtb:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|ht9jin:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>