Skip to content

Commit 80c716e

Browse files
authored
Merge pull request #630 from ibi-group/feature/DT-520-auto-fetch-memory-leak
Auto fetch memory leak
2 parents 6b80d74 + e5095e9 commit 80c716e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/main/java/com/conveyal/datatools/manager/models/FeedSource.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import java.io.File;
3737
import java.io.IOException;
38+
import java.io.InputStream;
3839
import java.net.HttpURLConnection;
3940
import java.net.MalformedURLException;
4041
import java.net.URL;
@@ -232,11 +233,12 @@ public FeedVersion fetch (MonitorableJob.Status status, String optionalUrlOverri
232233
conn.connect();
233234
return processFetchResponse(status, optionalUrlOverride, version, latest, new HttpURLConnectionResponse(conn));
234235
} catch (IOException e) {
235-
String message = String.format("Unable to connect to %s; not fetching %s feed", conn.getURL(), this.name); // url, this.name);
236-
LOG.error(message);
236+
String message = String.format("Unable to connect to %s; not fetching %s feed", conn.getURL(), this.name);
237+
LOG.error(message, e);
237238
status.fail(message);
238-
e.printStackTrace();
239239
return null;
240+
} finally {
241+
conn.disconnect();
240242
}
241243
}
242244

@@ -322,7 +324,9 @@ public FeedVersion processFetchResponse(
322324
status.update(message, 75.0);
323325
// Create new file from input stream (this also handles hashing the file and other version fields
324326
// calculated from the GTFS file.
325-
newGtfsFile = version.newGtfsFile(response.getInputStream());
327+
try (InputStream inputStream = response.getInputStream()) {
328+
newGtfsFile = version.newGtfsFile(inputStream);
329+
}
326330
break;
327331
case HttpURLConnection.HTTP_MOVED_TEMP:
328332
case HttpURLConnection.HTTP_MOVED_PERM:

src/main/java/com/conveyal/datatools/manager/persistence/FeedStore.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ public File newFeed (String id, InputStream inputStream, FeedSource feedSource)
139139
// NOTE: depending on the feed store, there may not be a feedSource provided (e.g., gtfsplus)
140140
File file = new File(path, id);
141141
LOG.info("Writing file to {}", file.getAbsolutePath());
142-
ByteStreams.copy(inputStream, new FileOutputStream(file));
142+
try (InputStream stream = inputStream; FileOutputStream outputStream = new FileOutputStream(file)) {
143+
ByteStreams.copy(stream, outputStream);
144+
}
143145
if (feedSource != null && !DataManager.useS3) {
144146
// Store latest as feed-source-id.zip if feedSource provided and if not using s3
145147
copyVersionToLatest(file, feedSource);

0 commit comments

Comments
 (0)