Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage memory leak fix #249

Merged
merged 5 commits into from Jan 21, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Revert "fs-storage: rm thunky"

This reverts commit 5a70596.
  • Loading branch information
astro committed Jan 21, 2015
commit 62f786c840b75d06b2f9928c893c7f66bf751eeb
@@ -9,6 +9,7 @@ var path = require('path')
var raf = require('random-access-file')
var rimraf = require('rimraf')
var Storage = require('./storage')
var thunky = require('thunky')

var TMP = fs.existsSync('/tmp') ? '/tmp' : os.tmpDir()
function noop () {}
@@ -46,7 +47,7 @@ function FSStorage (parsedTorrent, opts) {
var pieceLength = file.pieceLength
var filePath = path.join(self.path, file.path)

var openWrite = function (cb) {
var openWrite = thunky(function (cb) {
var fileDir = path.dirname(filePath)

mkdirp(fileDir, function (err) {
@@ -57,16 +58,16 @@ function FSStorage (parsedTorrent, opts) {
file.fd = fd
cb(null, fd)
})
}
})

var openRead = function (cb) {
var openRead = thunky(function (cb) {
// TODO: no need for fs.exists call, just try opening and handle error.
// fs.exists then open creates opportunity for race condition.
fs.exists(filePath, function (exists) {
if (exists) return openWrite(cb)
cb(self.nonExistentError)
})
}
})

file.pieces.forEach(function (piece) {
var index = piece.index
@@ -159,7 +160,6 @@ FSStorage.prototype._onPieceDone = function (piece) {
var writeToNextFile = function (err) {
if (err) return self.emit('error', err)
if (i >= end) {
delete piece.buffer
return cb()
}

@@ -63,6 +63,7 @@
"simple-get": "^1.0.0",
"simple-sha1": "^2.0.0",
"speedometer": "^0.1.2",
"thunky": "^0.1.0",
"torrent-discovery": "^2.0.1",
"ut_metadata": "^2.1.0",
"ut_pex": "^1.0.1",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.