From f50ad2aee6349de07c3b99314b6f8b3c2bef6f4a Mon Sep 17 00:00:00 2001 From: "@wwwjim" Date: Thu, 8 Oct 2020 21:46:21 -0700 Subject: [PATCH] recreate bucket bug: produced an interesting bug by messing up the first request --- scripts/recreate-bucket-bug.js | 73 +++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/scripts/recreate-bucket-bug.js b/scripts/recreate-bucket-bug.js index a272a37e..8319f63c 100644 --- a/scripts/recreate-bucket-bug.js +++ b/scripts/recreate-bucket-bug.js @@ -4,6 +4,7 @@ import * as Utilities from "~/node_common/utilities"; import configs from "~/knexfile"; import knex from "knex"; import FS from "fs"; +import AbortController from "abort-controller"; import { PrivateKey } from "@textile/hub"; import { execSync } from "child_process"; @@ -18,6 +19,12 @@ console.log(`RUNNING: recreate-bucket-bug.js`); const HIGH_WATER_MARK = 1024 * 1024 * 3; +function sleep(ms) { + return new Promise((resolve) => { + setTimeout(resolve, ms); + }); +} + const TEXTILE_KEY_INFO = { key: Environment.TEXTILE_HUB_KEY, secret: Environment.TEXTILE_HUB_SECRET, @@ -54,7 +61,11 @@ const run = async () => { console.log({ api }); - let { buckets, bucketKey } = await Utilities.getBucketAPIFromUserToken({ + let { + buckets, + bucketKey, + bucketRoot, + } = await Utilities.getBucketAPIFromUserToken({ user, bucketName: "delete-this-bucket", }); @@ -84,6 +95,16 @@ const run = async () => { const files = []; try { + // NOTE(jim): For Textile + // Uncommenting this block will trigger a bug we should + // Resolve first. + // ---------------------------------------------------------------- + + await execSync( + "dd if=/dev/random of=4GB_BUCKET_TEST.txt bs=1 count=0 seek=4g" + ); + files.push("4GB_BUCKET_TEST.txt"); + await execSync( "dd if=/dev/random of=200MB_BUCKET_TEST.txt bs=1 count=0 seek=200m" ); @@ -103,16 +124,6 @@ const run = async () => { "dd if=/dev/random of=2GB_BUCKET_TEST.txt bs=1 count=0 seek=2g" ); files.push("2GB_BUCKET_TEST.txt"); - - // NOTE(jim): For Textile - // Uncommenting this block will trigger a bug we should - // Resolve first. - // ---------------------------------------------------------------- - - await execSync( - "dd if=/dev/random of=4GB_BUCKET_TEST.txt bs=1 count=0 seek=4g" - ); - files.push("4GB_BUCKET_TEST.txt"); } catch (e) { reportError(e.message); } @@ -121,21 +132,47 @@ const run = async () => { // NOTE(jim): Try to upload each file the first time. // ---------------------------------------------------------------- + let firstTry = true; + let items; for (let i = 0; i < files.length; i++) { const file = files[i]; - + let controller = new AbortController(); + let { signal } = controller; const readStream = FS.createReadStream(`${file}`, { highWaterMark: HIGH_WATER_MARK, }); - reportTask(`attempting ${file} push to bucket`); - try { - await buckets.pushPath(bucketKey, file, readStream); - reportTask(`successfully added ${file}`); - } catch (e) { - reportError(e.message); + if (firstTry) { + firstTry = false; + + try { + buckets.pushPath(bucketKey, file, readStream, { + root: bucketRoot, + signal, + }); + + await sleep(5000); + + controller.abort(); + + reportTask(`aborted the first file: ${file}`); + + await sleep(5000); + } catch (e) { + reportError(e.message); + } + } else { + try { + await buckets.pushPath(bucketKey, file, readStream, { + root: bucketRoot, + signal, + }); + reportTask(`successfully added ${file}`); + } catch (e) { + reportError(e.message); + } } items = null;