<p>A minimum scope approach for JOSM could be as follows: it generates a new Idempotency-Key outside the retry look, and passes it as HTTP header for POST requests.</p>
<p>I also added some log file excerpts below to demo a chunked upload. Every single upload has its own Idempotency-Key. Towards the end, I shut down the Rails server, and JOSM did one unsuccessful post, followed by another 5 unsuccessful retries, each time sending the same Key.</p>
<p>Assuming we had some corresponding logic on the backend as well, this  would already improve today's situation. Of course there's always room for improvement, but I don't think this will add a massive burden to clients willing to implement this approach.</p>
<pre><code>Index: src/org/openstreetmap/josm/io/OsmApi.java
===================================================================

 import java.io.StringReader;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 import java.util.function.Consumer;

... 

     /**
      * Generic method for sending requests to the OSM API.
      *
     protected final String sendRequest(String requestMethod, String urlSuffix, String requestBody, ProgressMonitor monitor,
             boolean doAuthenticate, boolean fastFail) throws OsmTransferException {
         int retries = fastFail ? 0 : getMaxRetries();
+   
+        // Generate new Idempotency-Key
+        String idempotencyKey = UUID.randomUUID().toString();
 
         while (true) { // the retry loop
             try {
                     addAuth(client);
                 }
 
+                if ("POST".equals(requestMethod)) {
+                    client.setHeader("Idempotency-Key", idempotencyKey);
+                    Logging.info("Using Idempotency-Key " + idempotencyKey);
+                }
+


</code></pre>
<pre><code>2019-04-07 13:13:36.106 INFORMATION: OK
2019-04-07 13:13:36.208 INFORMATION: Using Idempotency-Key e8f69ee7-b958-4d95-a7bd-b0d964947cf5
changeset/1303/upload
2019-04-07 13:13:36.208 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (159 B) ...
2019-04-07 13:13:36.253 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload -> 200
2019-04-07 13:13:36.253 INFORMATION: OK
2019-04-07 13:13:36.355 INFORMATION: Using Idempotency-Key e8f40f0b-27c1-4934-93e3-3646f29dc245
changeset/1303/upload
2019-04-07 13:13:36.355 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...
2019-04-07 13:13:36.405 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload -> 200
2019-04-07 13:13:36.405 INFORMATION: OK
2019-04-07 13:13:36.507 INFORMATION: Using Idempotency-Key 973c9c41-fd18-4346-8536-00b55ab4e6e2
changeset/1303/upload
2019-04-07 13:13:36.507 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...
2019-04-07 13:13:36.553 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload -> 200
2019-04-07 13:13:36.553 INFORMATION: OK
2019-04-07 13:13:36.655 INFORMATION: Using Idempotency-Key 7f4c3f5b-3180-4dd9-b13b-f7e8d55246db
changeset/1303/upload
2019-04-07 13:13:36.655 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (159 B) ...
2019-04-07 13:13:36.701 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload -> 200
2019-04-07 13:13:36.701 INFORMATION: OK
2019-04-07 13:13:36.803 INFORMATION: Using Idempotency-Key ee95ef0f-e760-42fb-ac29-f25dcfeaff90
changeset/1303/upload
2019-04-07 13:13:36.803 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...
2019-04-07 13:13:36.804 INFORMATION: Using Idempotency-Key ee95ef0f-e760-42fb-ac29-f25dcfeaff90
changeset/1303/upload
2019-04-07 13:13:36.805 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...
2019-04-07 13:13:36.805 INFORMATION: Using Idempotency-Key ee95ef0f-e760-42fb-ac29-f25dcfeaff90
changeset/1303/upload
2019-04-07 13:13:36.806 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...
2019-04-07 13:13:36.806 INFORMATION: Using Idempotency-Key ee95ef0f-e760-42fb-ac29-f25dcfeaff90
changeset/1303/upload
2019-04-07 13:13:36.807 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...
2019-04-07 13:13:36.807 INFORMATION: Using Idempotency-Key ee95ef0f-e760-42fb-ac29-f25dcfeaff90
changeset/1303/upload
2019-04-07 13:13:36.807 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...
2019-04-07 13:13:36.808 INFORMATION: Using Idempotency-Key ee95ef0f-e760-42fb-ac29-f25dcfeaff90
changeset/1303/upload
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/issues/2201#issuecomment-480582206">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABWnLVuZn0ft1DbbDBW3XmYNY_mlFx9Aks5vedgJgaJpZM4cgFOf">mute the thread</a>.<img src="https://github.com/notifications/beacon/ABWnLR_rZfuiZay3rny6KJ_9aK6EycdRks5vedgJgaJpZM4cgFOf.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/openstreetmap/openstreetmap-website","title":"openstreetmap/openstreetmap-website","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/openstreetmap/openstreetmap-website"}},"updates":{"snippets":[{"icon":"PERSON","message":"@mmd-osm in #2201: A minimum scope approach for JOSM could be as follows: it generates a new Idempotency-Key outside the retry look, and passes it as HTTP header for POST requests.\r\n\r\nI also added some log file excerpts below to demo a chunked upload. Every single upload has its own Idempotency-Key. Towards the end, I shut down the Rails server, and JOSM did one unsuccessful post, followed by another 5 unsuccessful retries, each time sending the same Key.\r\n\r\nAssuming we had some corresponding logic on the backend as well, this  would already improve today's situation. Of course there's always room for improvement, but I don't think this will add a massive burden to clients willing to implement this approach.\r\n\r\n```\r\nIndex: src/org/openstreetmap/josm/io/OsmApi.java\r\n===================================================================\r\n\r\n import java.io.StringReader;\r\n import java.util.HashMap;\r\n import java.util.List;\r\n import java.util.Map;\r\n+import java.util.UUID;\r\n import java.util.function.Consumer;\r\n\r\n... \r\n\r\n     /**\r\n      * Generic method for sending requests to the OSM API.\r\n      *\r\n     protected final String sendRequest(String requestMethod, String urlSuffix, String requestBody, ProgressMonitor monitor,\r\n             boolean doAuthenticate, boolean fastFail) throws OsmTransferException {\r\n         int retries = fastFail ? 0 : getMaxRetries();\r\n+   \r\n+        // Generate new Idempotency-Key\r\n+        String idempotencyKey = UUID.randomUUID().toString();\r\n \r\n         while (true) { // the retry loop\r\n             try {\r\n                     addAuth(client);\r\n                 }\r\n \r\n+                if (\"POST\".equals(requestMethod)) {\r\n+                    client.setHeader(\"Idempotency-Key\", idempotencyKey);\r\n+                    Logging.info(\"Using Idempotency-Key \" + idempotencyKey);\r\n+                }\r\n+\r\n\r\n\r\n```\r\n\r\n\r\n```\r\n2019-04-07 13:13:36.106 INFORMATION: OK\r\n2019-04-07 13:13:36.208 INFORMATION: Using Idempotency-Key e8f69ee7-b958-4d95-a7bd-b0d964947cf5\r\nchangeset/1303/upload\r\n2019-04-07 13:13:36.208 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (159 B) ...\r\n2019-04-07 13:13:36.253 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload -\u003e 200\r\n2019-04-07 13:13:36.253 INFORMATION: OK\r\n2019-04-07 13:13:36.355 INFORMATION: Using Idempotency-Key e8f40f0b-27c1-4934-93e3-3646f29dc245\r\nchangeset/1303/upload\r\n2019-04-07 13:13:36.355 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...\r\n2019-04-07 13:13:36.405 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload -\u003e 200\r\n2019-04-07 13:13:36.405 INFORMATION: OK\r\n2019-04-07 13:13:36.507 INFORMATION: Using Idempotency-Key 973c9c41-fd18-4346-8536-00b55ab4e6e2\r\nchangeset/1303/upload\r\n2019-04-07 13:13:36.507 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...\r\n2019-04-07 13:13:36.553 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload -\u003e 200\r\n2019-04-07 13:13:36.553 INFORMATION: OK\r\n2019-04-07 13:13:36.655 INFORMATION: Using Idempotency-Key 7f4c3f5b-3180-4dd9-b13b-f7e8d55246db\r\nchangeset/1303/upload\r\n2019-04-07 13:13:36.655 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (159 B) ...\r\n2019-04-07 13:13:36.701 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload -\u003e 200\r\n2019-04-07 13:13:36.701 INFORMATION: OK\r\n2019-04-07 13:13:36.803 INFORMATION: Using Idempotency-Key ee95ef0f-e760-42fb-ac29-f25dcfeaff90\r\nchangeset/1303/upload\r\n2019-04-07 13:13:36.803 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...\r\n2019-04-07 13:13:36.804 INFORMATION: Using Idempotency-Key ee95ef0f-e760-42fb-ac29-f25dcfeaff90\r\nchangeset/1303/upload\r\n2019-04-07 13:13:36.805 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...\r\n2019-04-07 13:13:36.805 INFORMATION: Using Idempotency-Key ee95ef0f-e760-42fb-ac29-f25dcfeaff90\r\nchangeset/1303/upload\r\n2019-04-07 13:13:36.806 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...\r\n2019-04-07 13:13:36.806 INFORMATION: Using Idempotency-Key ee95ef0f-e760-42fb-ac29-f25dcfeaff90\r\nchangeset/1303/upload\r\n2019-04-07 13:13:36.807 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...\r\n2019-04-07 13:13:36.807 INFORMATION: Using Idempotency-Key ee95ef0f-e760-42fb-ac29-f25dcfeaff90\r\nchangeset/1303/upload\r\n2019-04-07 13:13:36.807 INFORMATION: POST http://localhost:3000/api/0.6/changeset/1303/upload (160 B) ...\r\n2019-04-07 13:13:36.808 INFORMATION: Using Idempotency-Key ee95ef0f-e760-42fb-ac29-f25dcfeaff90\r\nchangeset/1303/upload\r\n```\r\n\r\n"}],"action":{"name":"View Issue","url":"https://github.com/openstreetmap/openstreetmap-website/issues/2201#issuecomment-480582206"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/issues/2201#issuecomment-480582206",
"url": "https://github.com/openstreetmap/openstreetmap-website/issues/2201#issuecomment-480582206",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>