Fix connection leak for smart http connections

SmartHttpPushConnection: close InputStream and OutputStream after
processing. Wrap IOExceptions which aren't TransportExceptions already
as a TransportException.

Also-By: Matthias Sohn <matthias.sohn@sap.com>
Change-Id: I8e11d899672fc470c390a455dc86367e92ef9076
This commit is contained in:
Saša Živkov 2022-06-03 16:36:43 +02:00 committed by Matthias Sohn
parent c6b0ee04e4
commit 011c26ff36
1 changed files with 23 additions and 11 deletions

View File

@ -1294,13 +1294,18 @@ class SmartHttpFetchConnection extends BasePackFetchConnection {
}
@Override
protected void doFetch(final ProgressMonitor monitor,
final Collection<Ref> want, final Set<ObjectId> have,
final OutputStream outputStream) throws TransportException {
try {
svc = new MultiRequestService(SVC_UPLOAD_PACK);
init(svc.getInputStream(), svc.getOutputStream());
protected void doFetch(ProgressMonitor monitor, Collection<Ref> want,
Set<ObjectId> have, OutputStream outputStream)
throws TransportException {
svc = new MultiRequestService(SVC_UPLOAD_PACK);
try (InputStream svcIn = svc.getInputStream();
OutputStream svcOut = svc.getOutputStream()) {
init(svcIn, svcOut);
super.doFetch(monitor, want, have, outputStream);
} catch (TransportException e) {
throw e;
} catch (IOException e) {
throw new TransportException(e.getMessage(), e);
} finally {
svc = null;
}
@ -1324,12 +1329,19 @@ class SmartHttpPushConnection extends BasePackPushConnection {
}
@Override
protected void doPush(final ProgressMonitor monitor,
final Map<String, RemoteRefUpdate> refUpdates,
protected void doPush(ProgressMonitor monitor,
Map<String, RemoteRefUpdate> refUpdates,
OutputStream outputStream) throws TransportException {
final Service svc = new MultiRequestService(SVC_RECEIVE_PACK);
init(svc.getInputStream(), svc.getOutputStream());
super.doPush(monitor, refUpdates, outputStream);
Service svc = new MultiRequestService(SVC_RECEIVE_PACK);
try (InputStream svcIn = svc.getInputStream();
OutputStream svcOut = svc.getOutputStream()) {
init(svcIn, svcOut);
super.doPush(monitor, refUpdates, outputStream);
} catch (TransportException e) {
throw e;
} catch (IOException e) {
throw new TransportException(e.getMessage(), e);
}
}
}