Index: trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java	(revision 13212)
+++ trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java	(revision 13213)
@@ -14,4 +14,5 @@
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.gui.MainApplication;
+import org.openstreetmap.josm.gui.io.AsynchronousUploadPrimitivesTask;
 import org.openstreetmap.josm.gui.util.GuiHelper;
 
@@ -274,4 +275,12 @@
     @Override
     protected Collection<Layer> realRemoveSingleLayer(Layer layer) {
+        if ((layer instanceof OsmDataLayer) && (((OsmDataLayer) layer).isReadOnly())) {
+            GuiHelper.runInEDT(() -> JOptionPane.showMessageDialog(MainApplication.parent,
+                    tr("Trying to delete the layer with background upload. Please wait until the upload is finished.")));
+
+            // Return an empty collection for allowing to delete other layers
+            return new ArrayList<>();
+        }
+
         if (layer == activeLayer || layer == editLayer) {
             Layer nextActive = suggestNextActiveLayer(layer);
@@ -409,9 +418,15 @@
     @Override
     protected synchronized void realResetState() {
-        // active and edit layer are unset automatically
-        super.realResetState();
-
-        activeLayerChangeListeners.clear();
-        layerAvailabilityListeners.clear();
+        // Reset state if no asynchronous upload is under progress
+        if (!AsynchronousUploadPrimitivesTask.getCurrentAsynchronousUploadTask().isPresent()) {
+            // active and edit layer are unset automatically
+            super.realResetState();
+
+            activeLayerChangeListeners.clear();
+            layerAvailabilityListeners.clear();
+        } else {
+            GuiHelper.runInEDT(() -> JOptionPane.showMessageDialog(MainApplication.parent,
+                    tr("A background upload is already in progress. Cannot reset state until the upload is finished.")));
+        }
     }
 
