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

Building tdweb results in RangeError #2825

Open
teleothleo opened this issue Mar 21, 2024 · 6 comments
Open

Building tdweb results in RangeError #2825

teleothleo opened this issue Mar 21, 2024 · 6 comments

Comments

@teleothleo
Copy link

Hello!
I face this error while running build-tdlib.sh script.
I source emsdk (source "/usr/lib/emsdk/emsdk_env.sh") and I run emsdk activate 3.1.1 before executing all the commands provided here. Please tell me how to avoid that error.
Also, if there is such an option, please explain what should I do to build only wasm version suitable for React projects to avoid error while building asmjs one.

logs:

[ 98%] Linking CXX static library libtdclient.a
[ 98%] Built target tdclient
[ 98%] Building CXX object CMakeFiles/tdjson_private.dir/td/generate/auto/td/telegram/td_api_json.cpp.o
[ 98%] Building CXX object CMakeFiles/tdjson_private.dir/td/telegram/ClientJson.cpp.o
[ 98%] Linking CXX static library libtdjson_private.a
[ 98%] Built target tdjson_private
[ 98%] Building CXX object CMakeFiles/tdjson_static.dir/td/telegram/td_json_client.cpp.o
[100%] Building CXX object CMakeFiles/tdjson_static.dir/td/telegram/td_log.cpp.o
[100%] Linking CXX static library libtdjson_static.a
[100%] Built target tdjson_static
[100%] Building CXX object CMakeFiles/td_asmjs.dir/td/telegram/td_emscripten.cpp.o
[100%] Linking CXX executable td_asmjs.js
/usr/lib/emsdk/upstream/emscripten/third_party/terser/terser.js:5991
        if (self instanceof AST_Scope) {
                 ^

RangeError: Maximum call stack size exceeded
    at Function.[Symbol.hasInstance] (<anonymous>)
    at AST_LabeledStatement.<anonymous> (/usr/lib/emsdk/upstream/emscripten/third_party/terser/terser.js:5991:18)
    at /usr/lib/emsdk/upstream/emscripten/third_party/terser/terser.js:6275:22
    at Array.forEach (<anonymous>)
    at display_body (/usr/lib/emsdk/upstream/emscripten/third_party/terser/terser.js:6266:14)
    at /usr/lib/emsdk/upstream/emscripten/third_party/terser/terser.js:6330:17
    at /usr/lib/emsdk/upstream/emscripten/third_party/terser/terser.js:5754:19
    at OutputStream.with_indent (/usr/lib/emsdk/upstream/emscripten/third_party/terser/terser.js:5719:38)
    at Object.with_block (/usr/lib/emsdk/upstream/emscripten/third_party/terser/terser.js:5753:9)
    at print_braced (/usr/lib/emsdk/upstream/emscripten/third_party/terser/terser.js:6329:20)
Traceback (most recent call last):
  File "/usr/lib/emsdk/upstream/emscripten/em++.py", line 14, in <module>
    sys.exit(emcc.run(sys.argv))
             ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/emsdk/upstream/emscripten/emcc.py", line 1154, in run
    phase_post_link(options, state, wasm_target, wasm_target, target)
  File "/usr/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/emsdk/upstream/emscripten/emcc.py", line 2687, in phase_post_link
    phase_binaryen(target, options, wasm_target)
  File "/usr/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/emsdk/upstream/emscripten/emcc.py", line 3331, in phase_binaryen
    wasm2js = building.wasm2js(wasm2js_template,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/emsdk/upstream/emscripten/tools/building.py", line 1134, in wasm2js
    temp = js_optimizer(temp, passes)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/emsdk/upstream/emscripten/tools/building.py", line 617, in js_optimizer
    return js_optimizer.run(filename, passes)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/emsdk/upstream/emscripten/tools/js_optimizer.py", line 398, in run
    return run_on_js(filename, passes, extra_info=extra_info, just_split=just_split, just_concat=just_concat)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/emsdk/upstream/emscripten/tools/js_optimizer.py", line 301, in run_on_js
    filenames = shared.run_multiple_processes(commands, route_stdout_to_temp_files_suffix='js_opt.jo.js')
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/emsdk/upstream/emscripten/tools/shared.py", line 208, in run_multiple_processes
    raise Exception('Subprocess %d/%d failed (%s)! (cmdline: %s)' % (idx + 1, len(commands), returncode_to_str(finished_process.returncode), shlex_join(commands[idx])))
Exception: Subprocess 7/17 failed (returned 1)! (cmdline: /usr/lib/emsdk/node/15.14.0_64bit/bin/node /usr/lib/emsdk/upstream/emscripten/tools/acorn-optimizer.js /tmp/tmpmvtym89z.jsfunc_6.js minifyLocals minifyWhitespace last)
node:internal/fs/utils:323
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/tmp/tmptzme6aiu.jsfunc_9.js'
    at Object.openSync (node:fs:505:3)
    at Object.readFileSync (node:fs:401:35)
    at read (/usr/lib/emsdk/upstream/emscripten/tools/acorn-optimizer.js:20:13)
    at Object.<anonymous> (/usr/lib/emsdk/upstream/emscripten/tools/acorn-optimizer.js:1834:15)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/tmp/tmptzme6aiu.jsfunc_9.js'
}
node:internal/fs/utils:323
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/tmp/tmp_i_mogj5.jsfunc_10.js'
    at Object.openSync (node:fs:505:3)
    at Object.readFileSync (node:fs:401:35)
    at read (/usr/lib/emsdk/upstream/emscripten/tools/acorn-optimizer.js:20:13)
    at Object.<anonymous> (/usr/lib/emsdk/upstream/emscripten/tools/acorn-optimizer.js:1834:15)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/tmp/tmp_i_mogj5.jsfunc_10.js'
}
node:internal/fs/utils:323
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/tmp/tmpx74gi7io.jsfunc_8.js'
    at Object.openSync (node:fs:505:3)
    at Object.readFileSync (node:fs:401:35)
    at read (/usr/lib/emsdk/upstream/emscripten/tools/acorn-optimizer.js:20:13)
    at Object.<anonymous> (/usr/lib/emsdk/upstream/emscripten/tools/acorn-optimizer.js:1834:15)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/tmp/tmpx74gi7io.jsfunc_8.js'
}
make[3]: *** [CMakeFiles/td_asmjs.dir/build.make:112: td_asmjs.js] Error 1
make[2]: *** [CMakeFiles/Makefile2:546: CMakeFiles/td_asmjs.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:553: CMakeFiles/td_asmjs.dir/rule] Error 2
make: *** [Makefile:296: td_asmjs] Error 2

Also, when I run emcc --version, the version seems correct:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.1 (1934a98e709b57d3592b8272d3f1264a72c089e4)
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@levlam
Copy link
Contributor

levlam commented Mar 21, 2024

You can comment the last line in build-tdlib.sh to disable asmjs building.

@teleothleo
Copy link
Author

teleothleo commented Mar 22, 2024

You can comment the last line in build-tdlib.sh to disable asmjs building.

build-tdlib.sh went well! Now there are some errors during build-tdweb.sh though.

...

Run `npm audit` for details.

> tdweb@1.8.1 build
> webpack --mode production

Browserslist: caniuse-lite is outdated. Please run next command `npm update`
Hash: 01879bcdd631b5b1f5e1
Version: webpack 4.44.1
Time: 2685ms
Built at: 03/22/2024 12:03:06 PM
 4 assets
Entrypoint main = tdweb.js
 [7] ./src/worker.js 113 bytes {0} [not cacheable] [built]
 [9] multi ./src/index.js 28 bytes {0} [built]
[14] ../../src/methods/node.js (ignored) 15 bytes {0} [built]
[17] ./src/index.js + 9 modules 56.6 KiB {0} [built]
     | ./src/index.js 31.6 KiB [built]
     | ./src/logger.js 1.87 KiB [built]
     |     + 8 hidden modules
    + 14 hidden modules
Child worker:
     3 assets
    Entrypoint main = 531569a634d32bdb7d27.worker.js
     [6] ./src/prebuilt/release/td_wasm.wasm 83 bytes {0} [built]
     [7] (webpack)/buildin/global.js 472 bytes {0} [built]
     [9] ./node_modules/babel-loader/lib!./node_modules/eslint-loader!./src/worker.js + 2 modules 70.1 KiB {0} [built]
         | ./node_modules/babel-loader/lib!./node_modules/eslint-loader!./src/worker.js 61.1 KiB [built]
         | ./src/logger.js 1.87 KiB [built]
         | ./src/wasm-utils.js 7.08 KiB [built]
    [17] ./src/prebuilt/release/td_wasm.js 134 KiB {1} [built]
        + 14 hidden modules

    ERROR in ./src/worker.js (./node_modules/babel-loader/lib!./node_modules/eslint-loader!./src/worker.js)
    Module not found: Error: Can't resolve './prebuilt/release/td_asmjs.js' in '/home/etevve/0base/field/libs/td/example/web/tdweb/src'
     @ ./src/worker.js (./node_modules/babel-loader/lib!./node_modules/eslint-loader!./src/worker.js) 336:19-59

    ERROR in ./src/worker.js (./node_modules/babel-loader/lib!./node_modules/eslint-loader!./src/worker.js)
    Module not found: Error: Can't resolve './prebuilt/release/td_asmjs.js.mem' in '/home/etevve/0base/field/libs/td/example/web/tdweb/src'
     @ ./src/worker.js (./node_modules/babel-loader/lib!./node_modules/eslint-loader!./src/worker.js) 10:0-70 342:21-41

@levlam
Copy link
Contributor

levlam commented Mar 22, 2024

You need to remove mentions of asmjs from tdweb/src/worker.js.

@teleothleo
Copy link
Author

Yep, it worked! Thank you for your work and help!

@teleothleo
Copy link
Author

teleothleo commented Mar 22, 2024

Right now I am facing errors coming from TDLib that I've not seen before. I've cleaned the cache after the rebuid & upgrade.

the first error:

1.d3f734d351e5f398dac9.worker.js:2585 [ 0][t 0][1711119125.622000217][Binlog.cpp:332][!Binlog /Glider/dbfs/td.binlog]  Failed to validate binlog event [Error : 0 : CRC mismatch [actual:0x7144f2a1][expected:0xcd89428c]LogEvent[[id:0x00000000000000a8][type:17191][flags:0][data:176584]][/home/etevve/0base/field/libs/td/tddb/td/db/binlog/Binlog.cpp:141]] 
0002b1e8 000000a8 00000000 00004327 00000000 00000000 00000000
    at http://127.0.0.1:5173/6eb463deb9a15ec0e9b91524cb388c8f.wasm:wasm-function[31997]:0x748892
    at http://127.0.0.1:5173/6eb463deb9a15ec0e9b91524cb388c8f.wasm:wasm-function[17171]:0x41a3bb
    at http://127.0.0.1:5173/6eb463deb9a15ec0e9b91524cb388c8f.wasm:wasm-function[72]:0x24e7f
    at http://127.0.0.1:5173/6eb463deb9a15ec0e9b91524cb388c8f.wasm:wasm-function[7712]:0x21aa5f
    at http://127.0.0.1:5173/6eb463deb9a15ec0e9b91524cb388c8f.wasm:wasm-function[10278]:0x2a62ad
    at http://127.0.0.1:5173/6eb463deb9a15ec0e9b91524cb388c8f.wasm:wasm-function[10905]:0x2bfa1e
_emscripten_log_js @ 1.d3f734d351e5f398dac9.worker.js:2585
_emscripten_log @ 1.d3f734d351e5f398dac9.worker.js:2585
$func31997 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x748892
$func17171 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x41a3bb
$func72 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x24e7f
$func7712 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x21aa5f
$func10278 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x2a62ad
$func10905 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x2bfa1e
$func17347 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x4222a2
$func17355 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x422b39
$func32077 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x74af62
$func26496 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x5c5230
$func558 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x2c6fc
$func42307 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x82ec4e
$func5836 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x1ae009
$func19514 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x47d462
$func42271 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x82dafd
$func125 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x261da
$func695 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x2e61d
$func5332 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x11c48e
$func32050 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x749eaa
$func21469 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x4d20b5
$func11114 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x2c3f61
$func17958 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x43b2e1
$func20521 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x4b1c41
$oa @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x83efc4
ccall @ 1.d3f734d351e5f398dac9.worker.js:2585
(anonymous) @ 1.d3f734d351e5f398dac9.worker.js:2585
receive @ d3f734d351e5f398dac9.worker.js:5836
(anonymous) @ d3f734d351e5f398dac9.worker.js:5897
setTimeout (async)
scheduleReceiveIn @ d3f734d351e5f398dac9.worker.js:5896
scheduleReceive @ d3f734d351e5f398dac9.worker.js:5887
receive @ d3f734d351e5f398dac9.worker.js:5852
(anonymous) @ d3f734d351e5f398dac9.worker.js:5897
setTimeout (async)
scheduleReceiveIn @ d3f734d351e5f398dac9.worker.js:5896
scheduleReceiveSoon @ d3f734d351e5f398dac9.worker.js:5876
(anonymous) @ d3f734d351e5f398dac9.worker.js:5580
Module.websocket.emit @ 1.d3f734d351e5f398dac9.worker.js:2585
handleMessage @ 1.d3f734d351e5f398dac9.worker.js:2585
peer_socket_onmessage @ 1.d3f734d351e5f398dac9.worker.js:2585

and the second error:

1.d3f734d351e5f398dac9.worker.js:2585 [ 0][t 0][1711120477.958000183][FileManager.cpp:697][!GetChatRequest]  Check `Unreachable` failed
    at http://127.0.0.1:5173/6eb463deb9a15ec0e9b91524cb388c8f.wasm:wasm-function[31997]:0x748892
    at http://127.0.0.1:5173/6eb463deb9a15ec0e9b91524cb388c8f.wasm:wasm-function[17171]:0x41a3bb
    at http://127.0.0.1:5173/6eb463deb9a15ec0e9b91524cb388c8f.wasm:wasm-function[72]:0x24e7f
    at http://127.0.0.1:5173/6eb463deb9a15ec0e9b91524cb388c8f.wasm:wasm-function[65]:0x24c88
    at http://127.0.0.1:5173/6eb463deb9a15ec0e9b91524cb388c8f.wasm:wasm-function[9335]:0x27051c
    at http://127.0.0.1:5173/6eb463deb9a15ec0e9b91524cb388c8f.wasm:wasm-function[1274]:0x3aa48

Also this warning appears quite often:

1.d3f734d351e5f398dac9.worker.js:2585 __syscall_getsockname 9
___syscall_getsockname @ 1.d3f734d351e5f398dac9.worker.js:2585
$func4475 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0xe13b9
$func30822 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x6baf1e
$func46066 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x8fea29
$func25289 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x58fa8f
$func4817 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0xfd098
$func46164 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x90314e
$func7341 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x1fd854
$func11114 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x2c3f61
$func17958 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x43b2e1
$func20521 @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x4b1c41
$oa @ 6eb463deb9a15ec0e9b91524cb388c8f.wasm:0x83efc4
ccall @ 1.d3f734d351e5f398dac9.worker.js:2585
(anonymous) @ 1.d3f734d351e5f398dac9.worker.js:2585
receive @ d3f734d351e5f398dac9.worker.js:5836
(anonymous) @ d3f734d351e5f398dac9.worker.js:5897
setTimeout (async)
scheduleReceiveIn @ d3f734d351e5f398dac9.worker.js:5896
scheduleReceiveSoon @ d3f734d351e5f398dac9.worker.js:5876
(anonymous) @ d3f734d351e5f398dac9.worker.js:5580
Module.websocket.emit @ 1.d3f734d351e5f398dac9.worker.js:2585
handleMessage @ 1.d3f734d351e5f398dac9.worker.js:2585
peer_socket_onmessage @ 1.d3f734d351e5f398dac9.worker.js:2585

@teleothleo teleothleo reopened this Mar 22, 2024
@levlam
Copy link
Contributor

levlam commented Mar 22, 2024

Something is very wrong, First two crashes looks like memory corruption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants