Skip to content

Commit

Permalink
fix: fs-server fd泄露 #2878
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan committed Dec 27, 2024
1 parent b4eb20b commit bd7d87c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,19 @@ class FileOperationsHandler(
headers.contentLength = artifactInputStream.range.length
headers.set(HttpHeaders.ACCEPT_RANGES, "bytes")
headers.add("Content-Range", "bytes ${range.start}-${range.end}/${node.size}")
if (artifactInputStream is FileArtifactInputStream) {
(response as ZeroCopyHttpOutputMessage).writeWith(
artifactInputStream.file,
artifactInputStream.range.start,
artifactInputStream.range.length
).awaitSingleOrNull()
} else {
val source = RegionInputStreamResource(artifactInputStream, range.total!!)
val body = DataBufferUtils.read(source, DefaultDataBufferFactory.sharedInstance, DEFAULT_BUFFER_SIZE)
response.writeWith(body).awaitSingleOrNull()
artifactInputStream.use {
if (artifactInputStream is FileArtifactInputStream) {
(response as ZeroCopyHttpOutputMessage).writeWith(
artifactInputStream.file,
artifactInputStream.range.start,
artifactInputStream.range.length
).awaitSingleOrNull()
} else {
val source = RegionInputStreamResource(artifactInputStream, range.total!!)
val body =
DataBufferUtils.read(source, DefaultDataBufferFactory.sharedInstance, DEFAULT_BUFFER_SIZE)
response.writeWith(body).awaitSingleOrNull()
}
}
return ok().buildAndAwait()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ class CoArtifactDataReceiver(
if (inMemory) {
val cacheData = cacheData!!.copyOfRange(0, pos.toInt())
val buf = DefaultDataBufferFactory.sharedInstance.wrap(cacheData)
val filePath = this.filePath.apply { this.createFile() }
channel = withContext(Dispatchers.IO) {
AsynchronousFileChannel.open(filePath, StandardOpenOption.WRITE, StandardOpenOption.CREATE)
}
// val filePath = this.filePath.apply { this.createFile() }
// channel = withContext(Dispatchers.IO) {
// AsynchronousFileChannel.open(filePath, StandardOpenOption.WRITE, StandardOpenOption.CREATE)
// }
DataBufferUtils.write(Mono.just(buf), channel!!).awaitSingle()
inMemory = false
// help gc
Expand Down

0 comments on commit bd7d87c

Please sign in to comment.