8301004: httpclient: Add more debug to HttpResponseInputStream

Reviewed-by: jpai
This commit is contained in:
Daniel Fuchs 2023-01-25 13:33:22 +00:00
parent 74e1a8bfa8
commit c8ad600064

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -545,8 +545,10 @@ public class ResponseSubscribers {
@Override @Override
public void onSubscribe(Flow.Subscription s) { public void onSubscribe(Flow.Subscription s) {
Objects.requireNonNull(s); Objects.requireNonNull(s);
if (debug.on()) debug.log("onSubscribed called");
try { try {
if (!subscribed.compareAndSet(false, true)) { if (!subscribed.compareAndSet(false, true)) {
if (debug.on()) debug.log("Already subscribed: canceling");
s.cancel(); s.cancel();
} else { } else {
// check whether the stream is already closed. // check whether the stream is already closed.
@ -557,10 +559,14 @@ public class ResponseSubscribers {
closed = this.closed; closed = this.closed;
if (!closed) { if (!closed) {
this.subscription = s; this.subscription = s;
assert buffers.remainingCapacity() > 1; // should contain at least 2 // should contain at least 2
assert buffers.remainingCapacity() > 1
: "buffers capacity: " + buffers.remainingCapacity()
+ " closed: " + closed + " failed: " + failed;
} }
} }
if (closed) { if (closed) {
if (debug.on()) debug.log("Already closed: canceling");
s.cancel(); s.cancel();
return; return;
} }
@ -571,6 +577,8 @@ public class ResponseSubscribers {
} }
} catch (Throwable t) { } catch (Throwable t) {
failed = t; failed = t;
if (debug.on())
debug.log("onSubscribed failed", t);
try { try {
close(); close();
} catch (IOException x) { } catch (IOException x) {
@ -604,6 +612,8 @@ public class ResponseSubscribers {
@Override @Override
public void onError(Throwable thrwbl) { public void onError(Throwable thrwbl) {
if (debug.on())
debug.log("onError called: " + thrwbl);
subscription = null; subscription = null;
failed = Objects.requireNonNull(thrwbl); failed = Objects.requireNonNull(thrwbl);
// The client process that reads the input stream might // The client process that reads the input stream might
@ -618,6 +628,8 @@ public class ResponseSubscribers {
@Override @Override
public void onComplete() { public void onComplete() {
if (debug.on())
debug.log("onComplete called");
subscription = null; subscription = null;
onNext(LAST_LIST); onNext(LAST_LIST);
} }
@ -631,6 +643,8 @@ public class ResponseSubscribers {
s = subscription; s = subscription;
subscription = null; subscription = null;
} }
if (debug.on())
debug.log("close called");
// s will be null if already completed // s will be null if already completed
try { try {
if (s != null) { if (s != null) {