Skip to content

Commit bd7d87c

Browse files
committed
fix: fs-server fd泄露 #2878
1 parent b4eb20b commit bd7d87c

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/handler/FileOperationsHandler.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,19 @@ class FileOperationsHandler(
103103
headers.contentLength = artifactInputStream.range.length
104104
headers.set(HttpHeaders.ACCEPT_RANGES, "bytes")
105105
headers.add("Content-Range", "bytes ${range.start}-${range.end}/${node.size}")
106-
if (artifactInputStream is FileArtifactInputStream) {
107-
(response as ZeroCopyHttpOutputMessage).writeWith(
108-
artifactInputStream.file,
109-
artifactInputStream.range.start,
110-
artifactInputStream.range.length
111-
).awaitSingleOrNull()
112-
} else {
113-
val source = RegionInputStreamResource(artifactInputStream, range.total!!)
114-
val body = DataBufferUtils.read(source, DefaultDataBufferFactory.sharedInstance, DEFAULT_BUFFER_SIZE)
115-
response.writeWith(body).awaitSingleOrNull()
106+
artifactInputStream.use {
107+
if (artifactInputStream is FileArtifactInputStream) {
108+
(response as ZeroCopyHttpOutputMessage).writeWith(
109+
artifactInputStream.file,
110+
artifactInputStream.range.start,
111+
artifactInputStream.range.length
112+
).awaitSingleOrNull()
113+
} else {
114+
val source = RegionInputStreamResource(artifactInputStream, range.total!!)
115+
val body =
116+
DataBufferUtils.read(source, DefaultDataBufferFactory.sharedInstance, DEFAULT_BUFFER_SIZE)
117+
response.writeWith(body).awaitSingleOrNull()
118+
}
116119
}
117120
return ok().buildAndAwait()
118121
}

src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/storage/CoArtifactDataReceiver.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ class CoArtifactDataReceiver(
191191
if (inMemory) {
192192
val cacheData = cacheData!!.copyOfRange(0, pos.toInt())
193193
val buf = DefaultDataBufferFactory.sharedInstance.wrap(cacheData)
194-
val filePath = this.filePath.apply { this.createFile() }
195-
channel = withContext(Dispatchers.IO) {
196-
AsynchronousFileChannel.open(filePath, StandardOpenOption.WRITE, StandardOpenOption.CREATE)
197-
}
194+
// val filePath = this.filePath.apply { this.createFile() }
195+
// channel = withContext(Dispatchers.IO) {
196+
// AsynchronousFileChannel.open(filePath, StandardOpenOption.WRITE, StandardOpenOption.CREATE)
197+
// }
198198
DataBufferUtils.write(Mono.just(buf), channel!!).awaitSingle()
199199
inMemory = false
200200
// help gc

0 commit comments

Comments
 (0)