oven-sh / bun

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

CPU emulator leads to strange memory issues #3312

Open dtinth opened 1 year ago

dtinth commented 1 year ago

The solution

edited

Download the build of Bun with “baseline” in the name

https://github.com/oven-sh/bun/releases/latest/download/bun-linux-x64-baseline.zip

if using Proxmor, follow this screenshot

Original issue:


What version of Bun is running?

0.6.9

What platform is your computer?

Linux 5.4.0-45-generic x86_64 x86_64

What steps can reproduce the bug?

repro.js

Bun.serve()

(It is a minimal reproduction)

What is the expected behavior?

Bun starts a server (which does nothing).

What do you see instead?

1 | Bun.serve();
   ^
TypeError: 湕捩摯潨瑳慮敭⁳畭瑳愠牬慥祤戠湥潣敤潦⁲潮⹷渊睥唠䱒椨灮瑵⸩潨瑳慮敭猠潨汵潤琠敨琠楲正.硅数瑣摥䀠浩潰瑲琠瑳牡⁴楷桴愠猠牴湩牯甠汲⤨䠀呔⁐破⁸桷汩敲潳癬湩慰正条笧絳‧瑡✠獻
 code: "ERR_INVALID_ARG_TYPE"

      at �����������������������������������������:1:0

Additional information

The repro above is just for testing. I ran into this error while trying to run an actual app inside a Docker container.

I went ahead and downloaded https://github.com/oven-sh/bun/releases/download/bun-v0.6.9/bun-linux-x64.zip and run it outside the Docker container and get the same error and reduced the code to the above repro script. The host OS is Ubuntu 20.04.

Jarred-Sumner commented 9 months ago

It’s supposed to detect if avx & avx2 are supported and use the default build else use -baseline

Bun currently targets haswell (default) or nehalem (baseline, ~2012)

itpcc commented 9 months ago

@Jarred-Sumner Please check the link. It returned Not Found. Did you mean https://github.com/oven-sh/bun/releases/download/bun-v1.0.7/bun-linux-x64-baseline.zip ?

Danijel-Enoch commented 8 months ago

What is the solution pls?

still getting this: TypeError: 湕捩摯⁥潨瑳慮敭⁳畭瑳愠牬慥祤戠⁥湥潣敤⁤潦⁲潮⹷渊睥唠䱒椨灮瑵⸩潨瑳慮敭猠潨汵⁤潤琠敨琠楲正.慢敳剕⁉慣❮⁴慨敶愠甠敳湲浡⁥牯瀠獡睳

Screen Shot 2023-11-26 at 1 52 35 PM

My docker file Screen Shot 2023-11-26 at 1 53 17 PM

ahoys commented 8 months ago

Your CPU doesn't support AVX2. The first step is to make sure your CPU is recent enough for Bun.

In my case my development environment was running in a virtual machine that used CPU emulation that did not support AVX2. The solution for me was to bypass the emulation altogether and allow the VM to directly use Host CPU.

ncordin commented 7 months ago

Hello, sorry it's still not clear to me, and i'm still stuck with this ERR_INVALID_ARG_TYPE error :/

From my understading, Bun is compatible with non AVX2 machines, thanks to the baseline version. The install script is detecting AVX2 support, and fetch the correct version. Am I right?

But in my situation, it does not seems to works. I would like to run Bun on production on a VPS with Ubuntu 2204. The cat /proc/cpuinfo show my virtual CPU does not have AVX2. I think the install script correctly downloaded the baseline version.

Does that means i not to find another hoster? Thanks for your help :)

EDIT: It's working now :) I contacted my hosting provider, they migrate my VPS to a newer cluster. If it can help, here is the new cpuinfo:

processor   : 1
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz
stepping    : 7
microcode   : 0x1
cpu MHz     : 2299.998
cache size  : 16384 KB
physical id : 0
siblings    : 2
core id     : 1
cpu cores   : 2
apicid      : 1
initial apicid  : 1
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm pti tsc_adjust xsaveopt arat

Previously the CPU name something like "KVM Common CPU"

Zantier commented 7 months ago

I'm getting the same Issue on an Ubuntu VPS, where I can't change the VM settings. I'm getting the same issue whether I use the bun installer, or download the baseline version.

I'm using Bun v1.0.23, released on 2024-01-16

/z$ bun main.ts
1 | Bun.serve();
    ^
TypeError: 畂⹮敳癲⁥硥数瑣⁳湡漠橢捥t硅数瑣摥眠扥潳正瑥琠敢愠
 code: "ERR_INVALID_ARG_TYPE"

      at /z/main.ts:1:1
/z$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy
/z$ uname -a
Linux [redacted] 5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
/z$ grep avx2 /proc/cpuinfo
/z$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 15
model           : 107
model name      : QEMU Virtual CPU version 2.5+
stepping        : 1
microcode       : 0x1
cpu MHz         : 3599.936
cache size      : 16384 KB
physical id     : 0
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc nopl xtopology cpuid tsc_known_freq pni cx16 x2apic hypervisor lahf_lm cpuid_fault pti
bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips        : 7199.87
clflush size    : 64
cache_alignment : 128
address sizes   : 40 bits physical, 48 bits virtual
power management:

/z$
codehz commented 6 months ago

The bug is a memory issue. The text is stack memory

Doesn't reproduce on macOS, but will try on Linux

@Jarred-Sumner

湕捩摯潨瑳慮敭⁳畭瑳愠牬慥祤戠湥潣敤潦⁲潮⹷渊睥唠䱒椨灮瑵⸩潨瑳慮敭猠潨汵潤琠敨琠楲正.硅数瑣摥䀠浩潰瑲琠瑳牡⁴楷桴愠猠牴湩牯甠汲⤨䠀呔⁐破⁸桷汩敲潳癬湩慰正条笧絳‧瑡✠獻

I think it may not be a memory issue, it can be decoded into (unicode to iso-8859-1)

ÿþUnicode hostnames must already be encoded for now.
new URL(input).hostname should do the trick.

it exists in https://github.com/oven-sh/bun/blob/3447bc2ed3bd68b12729355cc5c132ddd5bc3503/src/bun.js/api/server.zig#L1003

and

畂⹮敳癲⁥硥数瑣⁳湡漠橢捥t硅数瑣摥眠扥潳正瑥琠敢愠

can be decoded into

ÿþBun.serve expects an object

while ÿþ = 0x255 0x254

Zantier commented 6 months ago

@codehz Thanks! I changed my code to:

Bun.serve({
  fetch(req, server) { },
});

And the error can be decoded with this python:

message = '湕捩摯⁥潨瑳慮敭⁳畭瑳愠牬慥祤戠⁥湥潣敤⁤潦⁲潮⹷渊睥唠䱒椨灮瑵⸩潨瑳慮敭猠潨汵⁤潤琠敨琠楲正.慢敳剕⁉慣❮⁴慨敶愠甠敳湲浡⁥牯瀠獡睳牯d'
message.encode('utf-16').decode('iso-8859-1')
"ÿþUnicode hostnames must already be encoded for now.\nnew URL(input).hostname should do the trick.\x00baseURI can't have a username or password\x00"

Edit: Error still happening in bun 1.0.25

hayzamjs commented 6 months ago
const fastify = require('fastify')({
    logger: false
})

const path = require('path')

fastify.register(require('@fastify/static'), {
    root: path.join(__dirname, 'public'),
})

fastify.listen({ port: 3000 }, (err, address) => {
    if (err) throw err
})

Throws very similar errors for me too, on a VM running inside Proxmox:

└──╼ #bun index.js 
229 |       return listenOptions.cb(new FST_ERR_REOPENED_SERVER(), null)
230 |     }
231 | 
232 |     server.once('error', wrap)
233 |     if (!this[kState].closing) {
234 |       server.listen(listenOptions, wrap)
            ^
TypeError: 湕捩摯潨瑳慮敭畭瑳愠牬慥祤戠湥潣敤⁤潦潮渊睥唠䱒椨灮瑵⸩潨瑳慮敭猠潨汵⁤潤琠敨琠楲正.慢敳剕⁉慣❮⁴慨敶愠甠敳湲浡牯瀠獡睳牯d
 code: "ERR_INVALID_ARG_TYPE"

      at node:http:424:69
      at /opt/Projects/Alchemilla/Landing/node_modules/fastify/lib/server.js:234:7
      at manageErr (/opt/Projects/Alchemilla/Landing/node_modules/fastify/fastify.js:595:11)
      at exit (/opt/Projects/Alchemilla/Landing/node_modules/fastify/lib/hooks.js:110:5)
      at next (/opt/Projects/Alchemilla/Landing/node_modules/fastify/lib/hooks.js:121:9)
      at hookRunnerApplication (/opt/Projects/Alchemilla/Landing/node_modules/fastify/lib/hooks.js:95:3)
      at /opt/Projects/Alchemilla/Landing/node_modules/fastify/fastify.js:577:11
      at _encapsulateThreeParam (/opt/Projects/Alchemilla/Landing/node_modules/avvio/boot.js:562:7)
      at timeoutCall (/opt/Projects/Alchemilla/Landing/node_modules/avvio/boot.js:458:5)
      at callWithCbOrNextTick (/opt/Projects/Alchemilla/Landing/node_modules/avvio/boot.js:440:7)
      at release (/opt/Projects/Alchemilla/Landing/node_modules/fastq/queue.js:149:9)
      at resume (/opt/Projects/Alchemilla/Landing/node_modules/fastq/queue.js:82:7)
      at /opt/Projects/Alchemilla/Landing/node_modules/avvio/boot.js:174:5
      at /opt/Projects/Alchemilla/Landing/node_modules/avvio/plugin.js:275:7
      at done (/opt/Projects/Alchemilla/Landing/node_modules/avvio/plugin.js:200:5)
      at check (/opt/Projects/Alchemilla/Landing/node_modules/avvio/plugin.js:224:9)

Bun version: 1.0.26

jameshibbard commented 5 months ago

I was running into exactly this issue on VBox and Bun v1.0.29. What worked for me was downloading and running Bun as an npm package. https://www.npmjs.com/package/@oven/bun-linux-x64-baseline

dtinth commented 5 months ago

@Jarred-Sumner Seems like people still have this issue, should this be reopened?

AriesAlex commented 4 months ago

can confirm still happening on bun 1.1.2 :(

kang49 commented 4 months ago

Confirm this issue still on Bun v.1.1.3

Ubantu version: Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-89-generic x86_64)

Screenshot 2024-04-11 at 17 26 27
nabildroid commented 3 months ago

same issue here!

VigilioYonatan commented 3 months ago

any solution in local found docker image. but in vps TypeError: 湕捩摯⁥潨瑳?

ChiChuRita commented 3 months ago

I have the same issues in Bun v1.1.8 on a VPS with baseline version

dtinth commented 3 months ago

Seems like people still have this issue, even with the baseline version, should this be reopened?

kcoderhtml commented 2 months ago

One way to solve this issue that I found for Proxmox is to set the VM CPU type to "Host" which fixes the issue for that VM.

Thanks to @ahoys for noticing this! https://github.com/oven-sh/bun/issues/3312#issuecomment-1836857963

nabildroid commented 2 months ago

how to set it?, like not everyone has the option to modify the type!

kcoderhtml commented 2 months ago

You have to be able to modify the vm settings, but once you can, you go to the hardware tab and then change the CPU type. image image image

yus-ham commented 2 months ago

For people who not able to set CPU type, you can try this Bun.serve() shim

https://gist.github.com/yus-ham/36f75733f26f832efe071664cf638054

Akumzy commented 2 months ago

For people who not able to set CPU type, you can try this Bun.serve() shim

https://gist.github.com/yus-ham/36f75733f26f832efe071664cf638054

 Starting...
yanm[Bun.serve] socket client open ...
yanm[Bun.serve] socket client open ...
============================================================
Bun v1.1.10 (5102a944) Linux x64 (baseline)
Args: "/home/nebor/bun-linux-x64-baseline/bun" "--bun" "server.js"
Features: jsc dotenv transpiler_cache(4)
Builtins: "bun:jsc" "bun:main" "node:async_hooks" "node:buffer" "node:child_process" "node:constants" "node:crypto" "node:events" "node:fs" "node:fs/promises" "node:http" "node:https" "node:module" "node:os" "node:path" "node:querystring" "node:stream" "node:string_decoder" "node:tty" "node:url" "node:util" "node:util/types" "node:zlib" "node:v8"
Elapsed: 38627ms | User: 39739ms | Sys: 26830ms
RSS: 16.63GB | Peak: 10.36GB | Commit: 16.63GB | Faults: 493

panic: Segmentation fault at address 0x585B6000000
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:

Illegal instruction (core dumped)