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

Try to make seeding procedure more robust #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions app/modules/seeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,31 @@ Seeder.prototype.seed = function () {
function (result, cb) {
torrentHash = result.torrentHash.toString('hex')
logger.debug('Added file to BitTorrent network, torrentHash: ', torrentHash, ' - #', index)
self.handler.shareMetadata(torrentHash, cb)
try {
self.handler.shareMetadata(torrentHash, function (err, result) {
if (err) {
// Try to remove metadata that might have already been inserted
try {
self.handler.removeMetadata(torrentHash, function dummy() {
});
}
catch(err) {}
cb(err);
}
else {
cb(null, result);
}
})
}
catch (err) {
// Try to remove metadata that might have already been inserted
try {
self.handler.removeMetadata(torrentHash, function dummy() {
});
}
catch(err) {}
cb(err);
}
},
function (result, cb) {
logger.debug('Started seeding, torrentHash: ', torrentHash, ' - #', index)
Expand All @@ -63,7 +87,12 @@ Seeder.prototype.seed = function () {
function (cb) {
logger.debug('Remove torrent, torrentHash: ', torrentHash, ' - #', index)
// stop seeding current files (otherwise they'll keep open I\O connections and re-announce)
self.handler.removeMetadata(torrentHash, cb)
try {
self.handler.removeMetadata(torrentHash, cb)
}
catch (err) {
cb(err);
}
}
],
function (err) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"async": "^2.1.4",
"aws-sdk": "^2.1.16",
"casimircore": "^0.11.3",
"cc-metadata-handler": "^0.6.0",
"cc-metadata-handler": "git://github.com/blockchainofthings/Metadata-Handler.git#BCoTv0.6.2",
"graceful-fs": "^4.1.2",
"jsonfile": "^2.0.0",
"jwt-simple": "^0.3.1",
Expand Down
6 changes: 6 additions & 0 deletions startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ folders.forEach(function (dir) {
}
})

// Trap unhandled exceptions to avoid application from aborting its processing
process.on('uncaughtException', (err) => {
logger.error('Unhandled exception.', err);
logger.debug('Continue processing...');
});

server.http_server.listen(server.port, function (err) {
if (err) {
logger.info('Critical Error so killing server - ' + err)
Expand Down