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

CPU emulator leads to strange memory issues #3312

Open
dtinth opened this issue Jun 14, 2023 · 72 comments
Open

CPU emulator leads to strange memory issues #3312

dtinth opened this issue Jun 14, 2023 · 72 comments
Labels
bug Something isn't working bun.js Something to do with a Bun-specific API

Comments

@dtinth
Copy link

dtinth commented Jun 14, 2023

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.

@dtinth dtinth added the bug Something isn't working label Jun 14, 2023
@trnxdev
Copy link
Contributor

trnxdev commented Jun 14, 2023

Can you change the name to something like "TypeError: Random symbols when calling Bun.serve()", it looks very weird and takes up too much space.

image
image

@trnxdev
Copy link
Contributor

trnxdev commented Jun 14, 2023

It might have something to do with your linux version, the recommended is 5.6+ (screenshot from readme)
image

@Jarred-Sumner
Copy link
Collaborator

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

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

@trnxdev
Copy link
Contributor

trnxdev commented Jun 14, 2023

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

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

I tried it on a recent version of linux, it just doesn't do anything. no output (just keeps it alive)
my linux version: Linux tiramifybox 6.3.6-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC x86_64 GNU/Linux

@cirospaciari
Copy link
Collaborator

cirospaciari commented Jun 14, 2023

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

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

on Debian 10 Kernel 4.19.0-24-amd64 and on Debian 12 Kernel 6.1.0-9-amd64, got no error, just keep the process alive because the server is alive on port 3000. Will try with Ubuntu 20.04

@Electroid Electroid changed the title TypeError: 湕捩摯潨瑳慮敭⁳畭瑳愠牬慥祤戠湥潣敤潦⁲潮⹷渊睥唠䱒椨灮瑵⸩潨瑳慮敭猠潨汵潤琠敨琠楲正.硅数瑣摥䀠浩潰瑲琠瑳牡⁴楷桴愠猠牴湩牯甠汲⤨䠀呔⁐破⁸桷汩敲潳癬湩慰正条笧絳‧瑡✠獻 at �����������������������������������������:1:0 when calling Bun.serve(). Bun.serve memory issue Jun 14, 2023
@trnxdev
Copy link
Contributor

trnxdev commented Jun 16, 2023

Will try with Ubuntu 20.04

Any progress on it? @cirospaciari

@cirospaciari
Copy link
Collaborator

We a

Will try with Ubuntu 20.04

Any progress on it? @cirospaciari

We added better validation on Bun.serve this probably solves the issue, can you check on the latest canary to see if it is solved?

@trnxdev
Copy link
Contributor

trnxdev commented Jun 16, 2023

@dtinth

@dtinth
Copy link
Author

dtinth commented Jun 16, 2023

Still error, but error message is now shorter:

$ wget https://github.com/oven-sh/bun/releases/download/canary/bun-linux-x64.zip

$ unzip bun-linux-x64.zip

$ ./bun-linux-x64/bun bug.js

1 | Bun.serve();
   ^
TypeError: 畂⹮敳癲硥数瑣⁳湡漠橢捥t慔扲污䙬楡敬呤䕯瑸慲瑣椀慭
 code: "ERR_INVALID_ARG_TYPE"

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

$ ./bun-linux-x64/bun bug.js 2>&1 | xxd
00000000: 3120 7c20 4275 6e2e 7365 7276 6528 293b  1 | Bun.serve();
00000010: 0a20 2020 5e0a 5479 7065 4572 726f 723a  .   ^.TypeError:
00000020: 20e7 9582 e2b9 aee6 95b3 e799 b2e2 81a5   ...............
00000030: e7a1 a5e6 95b0 e791 a3e2 81b3 e6b9 a1e6  ................
00000040: bca0 e6a9 a2e6 8da5 74e6 8594 e689 b2e6  ........t.......
00000050: b1a1 e499 ace6 a5a1 e695 ace5 91a4 e495  ................
00000060: afe7 91b8 e685 b2e7 91a3 e6a4 80e6 85ad  ................
00000070: 0a20 636f 6465 3a20 2245 5252 5f49 4e56  . code: "ERR_INV
00000080: 414c 4944 5f41 5247 5f54 5950 4522 0a0a  ALID_ARG_TYPE"..
00000090: 2020 2020 2020 6174 2000 0000 0000 0000        at .......
000000a0: 00aa aaaa aaaa aaaa aaaa aaaa aaaa aaaa  ................
000000b0: aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa  ................
000000c0: aaaa aaaa aaaa aaaa aaaa 3a31 3a30 0a    ..........:1:0.

@trnxdev
Copy link
Contributor

trnxdev commented Jul 28, 2023

@cirospaciari we hit another case, any further progress with this?
(^ see below)

@Northernside
Copy link

Northernside commented Jul 28, 2023

Also happening on my end (since bun 0.7.0)

Linux 5.10.0-23-amd64 x86_64 unknown
bun 0.7.1 (e110ccf)
(With OP's attached reproduction)

bun kartoffel.js 2>&1 | xxd:
https://paste.laby.net/gapavecusi.makefile

@Northernside
Copy link

I upgraded my Linux kernel to 6.4.0, hoping this would fix it, but unfortunately it doesn't (maybe this info helps? idk).
image

@cirospaciari
Copy link
Collaborator

cirospaciari commented Jul 28, 2023

Still not able to reproduce, @Northernside can you share more info about your system like processor name etc?

Some systems I tried:

OS: macOS 13.3 22E252 arm64
Kernel: 22.4.0

image

OS: Debian GNU/Linux trixie/sid x86_64
Kernel: 6.3.0-1-amd64

image

OS: Ubuntu 22.04.2 LTS x86_64
Kernel: 5.19.0-43-generic

image

and the same on Debian 10

image

basically, this is the expected behavior for Bun.serve() if you do not pass any object as an option. But not able to see the same broken text, looks like a memory issue.

@Northernside
Copy link

Northernside commented Jul 28, 2023

It didn't occur on my macOS (Sonoma, latest beta) but it does on my VPS hosted by Dashserv (German hoster).

My VPS runs under Qemu (at least that's what I believe?) so all hardware outputs tell some weird ass things, but anyway:
https://paste.laby.net/marupohehi.m (sudo lshw)
https://paste.laby.net/bukelaboti.cs (sudo lshw -short)
https://paste.laby.net/bisewahefo.sql (sudo lscpu)

According to my hoster, the CPU is an AMD Epyc 7443 4Ghz
image

@Northernside
Copy link

Also, I can give you full SSH access to my system on which it's bugging out lol - maybe this can help you debug stuff quicker?

@Jarred-Sumner
Copy link
Collaborator

The original bug was caused by incorrect arguments type checking in Bun.serve() and has since been fixed (as of Bun v0.6.11 or so).

The error @Northernside is seeing appears to be due to using bun-linux-x64 when the machine should be using bun-linux-x64-baseline. Bun's install script is meant to auto-detect this, but if installed through Docker or on a machine which does support avx2, it will install the wrong choice. @Northernside please use the .tar.gz from https://github.com/oven-sh/bun/releases/download/bun-${version}/bun-linux-x64-baseline.zip instead of https://github.com/oven-sh/bun/releases/download/bun-${version}/bun-linux-x64.zip. In the future, we will make this work better to not need this step.

@Northernside
Copy link

Sorry to bother you again, I don't know if I did something wrong, or not, but even when switching to -baseline, this issue still exists 👀

I made it so that it'll always grab the baseline archive in the installer (that's why I did the grep output, don't get confused).

Did I forget/do something wrong?
image

@Jarred-Sumner Jarred-Sumner reopened this Jul 29, 2023
@Northernside
Copy link

Any updates on this?
I wanted to note again that this only occurs since 0.7.0 (it all works perfectly fine in 0.6.9!) and it prevents me from being able to update & use newer versions and features.
No pressure of course, don't worry!

@Jarred-Sumner
Copy link
Collaborator

Any updates on this?
I wanted to note again that this only occurs since 0.7.0 (it all works perfectly fine in 0.6.9!) and it prevents me from being able to update & use newer versions and features.
No pressure of course, don't worry!

Does this happen for any call to Bun.serve() or specifically ones with invalid arguments (eg Bun.serve() or Bun.serve(Symbol())`)

It’s very confusing why this could still be happening and why it doesn’t seem to reproduce on any hardware I’ve tried.

@Northernside
Copy link

Does this happen for any call to Bun.serve() or specifically ones with invalid arguments (eg Bun.serve() or Bun.serve(Symbol())`)

Seems like it does happen on every Bun.serve() call:
image

It’s very confusing why this could still be happening and why it doesn’t seem to reproduce on any hardware I’ve tried.

I'm still up for giving you SSH access to my VPS with the affected hardware so that you can test/debug things etc.
What could have changed from 0.6.9 -> 0.7.0 that caused this?

@Northernside
Copy link

I know, I know, this might annoy you, but are you up to testing/debugging it with my hardware? I want to be able to use the newer versions of bun because they also fix a lot of issues which I'm currently experiencing on 0.6.9 (e.g. a LOT of segfaults and compatibility issues).

@Northernside
Copy link

Oh btw I have to correct myself, it's not from 0.6.9 -> 0.7.0 but from 0.6.9 -> 0.6.10 when this issue started occurring.

@Jarred-Sumner
Copy link
Collaborator

@Northernside if you explicitly set hostname in Bun.serve does that work, by chance? I have a hunch what the cause is

@Northernside
Copy link

It doesn't, unfortunately.
image

@pak-unyil
Copy link

I fix this issue by changing VPS provider

@Danijel-Enoch
Copy link

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
Copy link

ahoys commented Dec 1, 2023

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
Copy link

ncordin commented Jan 1, 2024

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
Copy link

Zantier commented Jan 17, 2024

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
Copy link
Contributor

codehz commented Jan 24, 2024

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

JSC.throwInvalidArguments("Unicode hostnames must already be encoded for now.\nnew URL(input).hostname should do the trick.", .{}, global, exception);

and

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

can be decoded into

ÿþBun.serve expects an object

while
ÿþ = 0x255 0x254

@Zantier
Copy link

Zantier commented Jan 24, 2024

@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
Copy link

hayzamjs commented Feb 5, 2024

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
Copy link

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
Copy link
Author

dtinth commented Feb 26, 2024

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

@AriesAlex
Copy link

can confirm still happening on bun 1.1.2 :(

@kang49
Copy link

kang49 commented Apr 11, 2024

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
Copy link

same issue here!

@VigilioYonatan
Copy link

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

@ChiChuRita
Copy link

ChiChuRita commented May 17, 2024

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

@dtinth
Copy link
Author

dtinth commented May 17, 2024

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

@kcoderhtml
Copy link

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! #3312 (comment)

@nabildroid
Copy link

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

@kcoderhtml
Copy link

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
Copy link
Contributor

yus-ham commented May 26, 2024

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

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

@Akumzy
Copy link

Akumzy commented May 26, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun.js Something to do with a Bun-specific API
Projects
None yet
Development

No branches or pull requests