oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.08k stars 2.76k forks source link

[windows] WebSocket index out of bounds #11192

Open Warchant opened 5 months ago

Warchant commented 5 months ago

How can we reproduce the crash?

  1. bun init - use all defaults
  2. Create index.ts from below code
  3. Run a ggxchain node:
docker run -it --rm -p 9944:9944 --entrypoint /usr/src/app/target/release/ggxchain-node ggxdocker/ggxnode:brooklyn-405e709 --dev --tmp --rpc-external
  1. bun run index.ts - run this on Windows 11. See log as below.

JavaScript/TypeScript code that reproduces the crash?


import { ApiPromise, Keyring, WsProvider } from "@polkadot/api";
import { cryptoWaitReady } from '@polkadot/util-crypto';

async function sendAndWaitForFinalized(tx: any, senderKeypair: any): Promise<void> {
    // Sign and send the transaction
    const unsub = await tx.signAndSend(senderKeypair, ({ status }: any) => {
        if (status.isInBlock) {
            console.log(`Transaction included at blockHash ${status.asInBlock}`);
        } else if (status.isFinalized) {
            console.log(`Transaction finalized at blockHash ${status.asFinalized}`);
            unsub();
        }
    });
}

async function main() {
    await cryptoWaitReady();

    // Construct
    const wsProvider = new WsProvider('ws://127.0.0.1:9944');
    const keyring = new Keyring({ type: 'sr25519' });
    const alice = keyring.addFromUri('//Alice');
    const bob = keyring.addFromUri('//Bob');

    const api = await ApiPromise.create({ provider: wsProvider });

    await api.isReadyOrError;

    try {
        // Send a transfer from Alice to Bob
        const transfer = api.tx.balances.transfer(bob.address, 12345);
        await sendAndWaitForFinalized(transfer, alice);

        // Query Bob's balance
        const { data: { free: previousFree }, nonce: previousNonce } = await api.query.system.account(bob.address);
        console.log(`Bob's balance is ${previousFree}, nonce is ${previousNonce}`);
    }
    catch (error) {
        console.log(error);
    }
}

main().catch(console.error);

Relevant log output

(3) > bun run index.ts
2024-05-20 12:42:16        API/INIT: RPC methods not decorated: btcRelay_verifyBlockHeaderInclusion, issue_getIssueRequests, issue_getVaultIssueRequests, oracle_collateralToWrapped, oracle_wrappedToCollateral, redeem_getRedeemRequests, redeem_getVaultRedeemRequests, replace_getNewVaultReplaceRequests, replace_getOldVaultReplaceRequests, vaultRegistry_getCollateralizationFromVault, vaultRegistry_getCollateralizationFromVaultAndCollateral, vaultRegistry_getIssueableTokensFromVault, vaultRegistry_getPremiumRedeemVaults, vaultRegistry_getRequiredCollateralForVault, vaultRegistry_getRequiredCollateralForWrapped, vaultRegistry_getVaultCollateral, vaultRegistry_getVaultTotalCollateral, vaultRegistry_getVaultsByAccountId, vaultRegistry_getVaultsWithIssuableTokens, vaultRegistry_getVaultsWithRedeemableTokens
2024-05-20 12:42:16        API/INIT: ggxchain-node/12: Not decorating unknown runtime apis: BtcRelayApi/1, VaultRegistryApi/1, IssueApi/1, RedeemApi/1, ReplaceApi/1
Bob's balance is 200000000000000000000012345, nonce is 0
============================================================
Bun v1.1.8 (89d25807) Windows x64
Args: "C:\Users\warch\scoop\apps\bun\current\bun.exe", "run", "index.ts"
Features: jsc transpiler_cache(5) tsconfig_paths(2) tsconfig(4) WebSocket 
Builtins: "bun:main" "node:buffer" "node:crypto" "node:string_decoder" "node:util" "node:util/types" "ws" "node-fetch" 
RSS: 0.37GB | Peak: 0.37GB | Commit: 4.74GB | Faults: 93033

panic(main thread): index out of bounds
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

To send a redacted crash report to Bun's team,
please file a GitHub issue using the link below:

 https://bun.report/1.1.8/wr189d2580AiggggX2j59Qk7z6Ts369Qu9ir2C8u0ne4ttkegzqkek37xG2t9t1C6r+pFA0eNrLzEtJrVDILy1RyE9TSMovzUspBgBHeAcx

Stack Trace (bun.report)

Bun v1.1.8 (89d2580) on windows x86_64 [RunCommand]

panic: index out of bounds

Warchant commented 5 months ago

Same for 1.1.9:

Bun v1.1.9 (bb13798) on windows x86_64 [RunCommand]

panic: index out of bounds