9df27d2ca511fbb3f2ab62154e3290d70758c957
markd
  Tue Dec 11 02:40:52 2018 -0800
added comments based on discoveries made while looking at the code

diff --git src/lib/udc.c src/lib/udc.c
index aa4c2dd..8568fef 100644
--- src/lib/udc.c
+++ src/lib/udc.c
@@ -217,57 +217,59 @@
     if (rd < 0)
 	errnoAbort("udcReadAndIgnore: error reading socket after %lld bytes", total);
     remaining -= rd;
     total += rd;
     }
 if (total < size)
     errAbort("udcReadAndIgnore: got EOF at %lld bytes (wanted %lld)", total, size);
 }
 
 static int connInfoGetSocket(struct udcFile *file, char *url, bits64 offset, int size)
 /* If ci has an open socket and the given offset matches ci's current offset,
  * reuse ci->socket.  Otherwise close the socket, open a new one, and update ci,
  * or return -1 if there is an error opening a new one. */
 {
 struct connInfo *ci = &file->connInfo;
-if (ci != NULL && ci->socket > 0 && ci->offset != offset)
+if (FALSE&& ci != NULL && ci->socket > 0 && ci->offset != offset)
     {
     bits64 skipSize = (offset - ci->offset);
     if (skipSize > 0 && skipSize <= MAX_SKIP_TO_SAVE_RECONNECT)
 	{
 	verbose(4, "!! skipping %lld bytes @%lld to avoid reconnect\n", skipSize, ci->offset);
 	udcReadAndIgnore(&file->ios.net, ci->socket, skipSize);
 	ci->offset = offset;
         file->ios.numReuse++;
 	}
     else
 	{
 	verbose(4, "Offset mismatch (ci %lld != new %lld), reopening.\n", ci->offset, offset);
 	mustCloseFd(&(ci->socket));
 	if (ci->ctrlSocket > 0)
 	    mustCloseFd(&(ci->ctrlSocket));
 	ZeroVar(ci);
 	}
     }
 int sd;
 if (ci == NULL || ci->socket <= 0)
     {
     file->ios.numConnects++;
     if (ci->redirUrl)
 	{
 	url = transferParamsToRedirectedUrl(url, ci->redirUrl);
 	}
+    // IMPORTANT NOTE: byterange is not a real URL parameter, this is a hack to pass
+    // the range to the net.c functions, which then parse it.
     char rangeUrl[2048];
     if (ci == NULL)
 	{
 	safef(rangeUrl, sizeof(rangeUrl), "%s;byterange=%lld-%lld",
 	      url, offset, (offset + size - 1));
 	sd = netUrlOpen(rangeUrl);
 	}
     else
 	{
 	safef(rangeUrl, sizeof(rangeUrl), "%s;byterange=%lld-", url, offset);
 	sd = ci->socket = netUrlOpenSockets(rangeUrl, &(ci->ctrlSocket));
 	ci->offset = offset;
 	}
     if (sd < 0)
 	return -1;
@@ -1534,32 +1536,36 @@
     if (fetchedEnd < file->endData)
         fetchedEnd = file->endData;
     }
 file->startData = fetchedStart;
 file->endData = fetchedEnd;
 }
 
 static boolean udcCachePreload(struct udcFile *file, bits64 offset, bits64 size)
 /* Make sure that given data is in cache - fetching it remotely if need be. 
  * Return TRUE on success. */
 {
 if (!udcCacheEnabled())
     return TRUE;
 
 boolean ok = TRUE;
-/* We'll break this operation into blocks of a reasonable size to allow
- * other processes to get cache access, since we have to lock the cache files. */
+/* Original comment said:
+ *  "We'll break this operation into blocks of a reasonable size to allow
+ *   other processes to get cache access, since we have to lock the cache files."
+ * However there is no locking done, so this whole splitting might be unnecessary
+ * complexity.
+ */
 bits64 s,e, endPos=offset+size;
 for (s = offset; s < endPos; s = e)
     {
     /* Figure out bounds of this section. */
     e = s + udcMaxBytesPerRemoteFetch;
     if (e > endPos)
 	e = endPos;
 
     struct udcBitmap *bits = file->bits;
     if (bits->version == file->bitmapVersion)
 	{
         udcFetchMissing(file, bits, s, e);
 	}
     else
 	{