jdyer1 commented on code in PR #2259:
URL: https://github.com/apache/solr/pull/2259#discussion_r1506577750


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrJdkClient.java:
##########
@@ -210,50 +243,50 @@ private HttpResponse<InputStream> doPutOrPost(
     }
 
     HttpRequest.BodyPublisher bodyPublisher;
-    final PipedOutputStream source;
+    Future<?> contentWritingFuture = null;
     if (contentWriter != null) {
-      source = new PipedOutputStream();
-      PipedInputStream sink = new PipedInputStream(source);
+
+      final PipedOutputStream source = new PipedOutputStream();
+      final PipedInputStream sink = new PipedInputStream(source);
       bodyPublisher = HttpRequest.BodyPublishers.ofInputStream(() -> sink);
-      // NOCOMMIT - this does not work.  The call to "client.send" sometimes 
will throw an
-      // IOException
-      // because our thread closes the outputstream too early.  But if we wait 
to close it until
-      // after the response returns, "client.send" blocks.
-      executor.submit(
-          () -> {
-            try (source) {
-              contentWriter.write(source);
-            } catch (Exception e) {
-              log.error("Cannot write Content Stream", e);
-            }
-          });
+
+      contentWritingFuture =
+          executor.submit(
+              () -> {
+                try (source) {
+                  contentWriter.write(source);
+                } catch (Exception e) {
+                  log.error("Cannot write Content Stream", e);
+                }
+              });
     } else if (streams != null && streams.size() == 1) {
-      source = null;
       InputStream is = streams.iterator().next().getStream();
       bodyPublisher = HttpRequest.BodyPublishers.ofInputStream(() -> is);
     } else if (queryParams != null && urlParamNames != null) {
-      source = null;
       ModifiableSolrParams requestParams = queryParams;
       queryParams = calculateQueryParams(urlParamNames, requestParams);
       queryParams.add(calculateQueryParams(solrRequest.getQueryParams(), 
requestParams));
       bodyPublisher = 
HttpRequest.BodyPublishers.ofString(requestParams.toString());
     } else {
-      source = null;
       bodyPublisher = HttpRequest.BodyPublishers.noBody();
     }
+
     if (isPut) {
       reqb.PUT(bodyPublisher);
     } else {
       reqb.POST(bodyPublisher);
     }
     decorateRequest(reqb, solrRequest);
     reqb.uri(new URI(url + "?" + queryParams));
-    HttpResponse<InputStream> response =
-        client.send(reqb.build(), HttpResponse.BodyHandlers.ofInputStream());
+
+    HttpResponse<InputStream> response;
     try {
-      source.close();
-    } catch (Exception e1) {
-      // ignore
+      response = client.send(reqb.build(), 
HttpResponse.BodyHandlers.ofInputStream());
+    } catch (IOException | InterruptedException | RuntimeException e) {
+      if (contentWritingFuture != null) {
+        contentWritingFuture.cancel(true);
+      }
+      throw e;
     }

Review Comment:
   yes, good _catch_ here.  I changed it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to