diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 56dbc5809..e8c91fd83 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "3.1.3", + "version": "3.1.4", "main": "package.json", "author": "undefined ", "repository": "https://github.com/hydro-dev/Hydro.git", @@ -14,9 +14,9 @@ "mongodb": "^3.7.3", "p-queue": "^7.3.0", "schemastery": "^3.5.4", - "shell-quote": "^1.7.3", + "shell-quote": "^1.7.4", "superagent": "^8.0.2", - "ws": "^8.9.0" + "ws": "^8.10.0" }, "preferUnplugged": true, "license": "AGPL-3.0-or-later", diff --git a/packages/hydrojudge/src/hosts/hydro.ts b/packages/hydrojudge/src/hosts/hydro.ts index cd0709dfa..50ca35711 100644 --- a/packages/hydrojudge/src/hosts/hydro.ts +++ b/packages/hydrojudge/src/hosts/hydro.ts @@ -54,6 +54,9 @@ export default class Hydro { await Lock.acquire(`${this.config.host}/${source}`); try { return await this._cacheOpen(source, files, next); + } catch (e) { + log.warn('CacheOpen Fail: %s %o %o', source, files, e); + throw e; } finally { Lock.release(`${this.config.host}/${source}`); } @@ -87,14 +90,22 @@ export default class Hydro { pid: +pid, files: filenames, }); + if (!res.body.links) throw new FormatError('problem not exist'); // eslint-disable-next-line no-inner-declarations async function download(name: string) { if (name.includes('/')) await fs.ensureDir(path.join(filePath, name.split('/')[0])); const w = fs.createWriteStream(path.join(filePath, name)); this.get(res.body.links[name]).pipe(w); await new Promise((resolve, reject) => { - w.on('finish', resolve); - w.on('error', (e) => reject(new Error(`DownloadFail(${name}): ${e.message}`))); + const timeout = setTimeout(() => reject(new Error(`DownloadTimeout(${name}, 60s)`)), 60000); + w.on('error', (e) => { + clearTimeout(timeout); + reject(new Error(`DownloadFail(${name}): ${e.message}`)); + }); + w.on('finish', () => { + clearTimeout(timeout); + resolve(null); + }); }); } const tasks = []; diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 7893a45ce..1e83d9b93 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "4.2.15", + "version": "4.2.16", "bin": "bin/hydrooj.js", "main": "src/plugin-api", "module": "src/plugin-api", diff --git a/packages/hydrooj/src/handler/judge.ts b/packages/hydrooj/src/handler/judge.ts index 3188f93e6..fa80a3a18 100644 --- a/packages/hydrooj/src/handler/judge.ts +++ b/packages/hydrooj/src/handler/judge.ts @@ -151,6 +151,7 @@ export class JudgeFilesDownloadHandler extends Handler { @post('pid', Types.UnsignedInt) async post(domainId: string, files: Set, pid: number) { const pdoc = await problem.get(domainId, pid); + if (!pdoc) this.response.body.links = null; const links = {}; for (const file of files) { // eslint-disable-next-line no-await-in-loop