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

Jestが突然終了する時がある #9096

Closed
syuilo opened this issue Sep 19, 2022 · 83 comments
Closed

Jestが突然終了する時がある #9096

syuilo opened this issue Sep 19, 2022 · 83 comments
Labels
⚠️bug? This might be a bug 🛠️Dev Development of Misskey itself 🔥high priority ❓needs more investigation A bug whose causes are unknown

Comments

@syuilo
Copy link
Member

syuilo commented Sep 19, 2022

テストの途中で exit status 1 でプロセスが終了することがある(エラーなどは吐かない)

@syuilo syuilo added ❓needs more investigation A bug whose causes are unknown ⚠️bug? This might be a bug 🛠️Dev Development of Misskey itself labels Sep 19, 2022
@syuilo
Copy link
Member Author

syuilo commented Sep 19, 2022

tasukete

@syuilo syuilo changed the title JestがGitHub Actions上で動かない JestがGitHub Actions上で動かない時がある Sep 19, 2022
@syuilo

This comment was marked as outdated.

@syuilo
Copy link
Member Author

syuilo commented Sep 19, 2022

エラーもなんも吐かないから手掛かりが全くない

@syuilo syuilo changed the title JestがGitHub Actions上で動かない時がある JestがGitHub Actions上で突然終了する時がある Sep 19, 2022
@syuilo

This comment was marked as outdated.

@syuilo
Copy link
Member Author

syuilo commented Sep 20, 2022

ちなみにテストは test/unit 下にあるものしかやらないようにしている

@syuilo

This comment was marked as outdated.

@syuilo
Copy link
Member Author

syuilo commented Sep 20, 2022

メモリを少なくとも500MBくらい消費してることが判明した
これが原因である可能性ありそう

@syuilo
Copy link
Member Author

syuilo commented Sep 20, 2022

ほぼ空のテストファイルでも150MBほどメモリ消費した
ts-jestが非常に怪しい

@syuilo
Copy link
Member Author

syuilo commented Sep 20, 2022

似たような問題が報告されていた
jestjs/jest#11601

@syuilo
Copy link
Member Author

syuilo commented Sep 20, 2022

懸賞金 ¥6000

@syuilo
Copy link
Member Author

syuilo commented Sep 20, 2022

ts-jestやめてesbuild-jestとか使うと解決するかなと思ったけど上手く動かなかった

@syuilo
Copy link
Member Author

syuilo commented Sep 21, 2022

あーキャッシュが無い状態でやると必ず再現しそう

@syuilo
Copy link
Member Author

syuilo commented Sep 21, 2022

いや関係なかった

@syuilo
Copy link
Member Author

syuilo commented Sep 21, 2022

swc使ってみたけど、動くときもあるけどやっぱり突然終了するときもある
ts-jest関係ないかも

@syuilo
Copy link
Member Author

syuilo commented Sep 21, 2022

tasukete

@syuilo
Copy link
Member Author

syuilo commented Sep 21, 2022

  • --runInBandは外しても発生することがあるためそれは関係なさそう
  • テストファイルの先頭にconsole.log書いてみたけど、突然終了するときはそれすらも呼ばれない

@syuilo
Copy link
Member Author

syuilo commented Sep 21, 2022

懸賞金 ¥7000

@syuilo
Copy link
Member Author

syuilo commented Sep 21, 2022

Chromeのデバッガ繋いだ時に限って再現しなくなる

@syuilo
Copy link
Member Author

syuilo commented Sep 21, 2022

関係あるか分からないけどたまにこれが出るときがある(これが出るときは突然終了しない場合)
image

@syuilo
Copy link
Member Author

syuilo commented Sep 21, 2022

ヌァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァンンンンオオオオンンオンオンオンオンンンンンンンンン゛ン゛!!!!!!!!!!!!!!!!

@syuilo syuilo changed the title JestがGitHub Actions上で突然終了する時がある Jestが突然終了する時がある Sep 21, 2022
@syuilo

This comment was marked as outdated.

@syuilo
Copy link
Member Author

syuilo commented Sep 21, 2022

ここまで来るとあとはJestのコードリーディングしてプリントデバッグするくらいしかなさそう

@syuilo
Copy link
Member Author

syuilo commented Sep 22, 2022

こまこまのこまり

@syuilo
Copy link
Member Author

syuilo commented Sep 23, 2022

あとはこんな感じでタイムアウトとthe user is already existsがたまにある

image

これらはこっちでは出たことないな

@syuilo
Copy link
Member Author

syuilo commented Sep 23, 2022

jsonldをimportするコードが含まれるのがRelayServiceだからSegfaultもそれに関係してるかも?

@ikuradon
Copy link
Contributor

手元で検証してみたところ、Node.js 16だと問題なく、18だとSegmentation faultを出すのかな
https://github.com/misskey-dev/misskey/blob/develop/.github/workflows/test.yml#L16
で18を指定しているっぽい?

@CyberRex0
Copy link
Contributor

クラッシュしなかった
Node 18.5 + Ubuntu 20.04.5 LTS
AMD EPYC 7282 16-Core Processor

@tamaina
Copy link
Member

tamaina commented Sep 23, 2022

image

MetaSeriviceでもSegfaultした

@tamaina
Copy link
Member

tamaina commented Sep 23, 2022

SegfaultはOCI A1 (arm64)特有の問題かもしれない

@syuilo
Copy link
Member Author

syuilo commented Sep 23, 2022

ちなみに私はずっとwindows + node 16で検証してました

@tamaina
Copy link
Member

tamaina commented Sep 23, 2022

ところで: --detectOpenHandles試したことある?

@syuilo
Copy link
Member Author

syuilo commented Sep 23, 2022

ところで: --detectOpenHandles試したことある?

むしろずっとそれしてたけどパフォーマンスに影響があるらしいからやめた

@tamaina
Copy link
Member

tamaina commented Sep 23, 2022

いま外出先なのでスクショ貼れないんだけど、--detectOpenHandlesだと必ず最後にhttp2ストリームが残っててなんとかかんとかって言われるので、ky-universalが何か関与してる?

@tamaina
Copy link
Member

tamaina commented Sep 23, 2022

image

@tamaina
Copy link
Member

tamaina commented Sep 23, 2022

SegfaultはOCI A1 (arm64)特有の問題かもしれない

x64なWSL2 Ubuntuでも再現した

@syuilo
Copy link
Member Author

syuilo commented Sep 24, 2022

image

まあこれはライブラリの仕様(importしただけで副作用を発生させるのは問題な気はする)だからしょうがないわね

@ikuradon
Copy link
Contributor

メモリリークが原因かと思って同じテストを11回ずつまわしてるけど全然落ちないわね…
image

yarn: 1.22.19
node: v16.17.0
command: rm -rf /tmp/jest_0/ && NODE_ENV=test node --expose-gc --experimental-vm-modules --experimental-import-meta-resolve node_modules/jest/bin/jest.js --forceExit --runInBand --detectOpenHandles --logHeapUsage

@syuilo
Copy link
Member Author

syuilo commented Sep 24, 2022

Note: このコミットで一時的に原因と思われる箇所を消してるので、再現させたい時はこれより前の状態でやった方が良いかも
da88e3a

@syuilo
Copy link
Member Author

syuilo commented Sep 24, 2022

そのコミット以降Actions上で一回も異常終了してないからやっぱりjsonldパッケージが原因ということで間違いなさそうになってきた

@ikuradon
Copy link
Contributor

Segmentation fault再現してます
image

yarn: 1.22.19
node: v16.17.0
commit: dabe5bf

@CyberRex0
Copy link
Contributor

Apple Siliconだと発現しない
Node 16で動かしてる

@ikuradon
Copy link
Contributor

Apple Siliconだと発現しない Node 16で動かしてる

MetaService.tsを複数コピーして(for i in {1..10};do cp test/unit/MetaService.{,$i.}ts;done)動かすと落ちる確率が上がるけどどうなんじゃろ

@CyberRex0
Copy link
Contributor

MetaService.tsを複数コピーして(for i in {1..10};do cp test/unit/MetaService.{,$i.}ts;done)動かすと落ちる確率が上がるけどどうなんじゃろ

クラッシュしなかった

@ikuradon
Copy link
Contributor

依然として落ちる環境と落ちない環境の違いがよくわかりませんが、jsonldにパッチを当てたところ落ちなくなった気がするので貼っておきます

--- node_modules/jsonld/lib/jsonld.orig.js      2022-09-25 10:34:08.252571149 +0000
+++ node_modules/jsonld/lib/jsonld.js   2022-09-25 09:28:59.067598275 +0000
@@ -34,7 +34,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 const canonize = require('rdf-canonize');
-const platform = require('./platform');
+// const platform = require('./platform');
 const util = require('./util');
 const ContextResolver = require('./ContextResolver');
 const IdentifierIssuer = util.IdentifierIssuer;
@@ -1017,8 +1017,8 @@
        /* WebIDL API */
        jsonld.JsonLdProcessor = require('./JsonLdProcessor')(jsonld);
 
-       platform.setupGlobals(jsonld);
-       platform.setupDocumentLoaders(jsonld);
+       // platform.setupGlobals(jsonld);
+       // platform.setupDocumentLoaders(jsonld);
 
        function _setDefaults(options, {
                documentLoader = jsonld.documentLoader,

@cffnpwr
Copy link
Contributor

cffnpwr commented Sep 27, 2022

色々やってたら落ちなくなったので報告します

MetaService.tsだけで落ちてる感じなのでこれを除いてJestを動かして見たら動いたので、このファイルが怪しいなという感じで色々してみました
どうやらファイル内にテストが1つもない状態が良くないらしく以下のような絶対成功するテストを追加してyarn jestを実行したら通りました

//  絶対に成功するテスト
it('alwaysCorrectTest', () => {
    expect(true).toBe(true);
});

以下環境です
OS: Ubuntu 22.04.1 LTS x86_64
node: v18.9.1
yarn: 1.22.19
commit: df0a90f

@syuilo
Copy link
Member Author

syuilo commented Sep 27, 2022

MetaServiceで落ちてるのはまた別の問題ですね
このIssueの内容としてはテスト実行中に突然exit code 1で異常終了するというもので、これはMetaServiceのテストファイルが無い状態でも再現します

@cffnpwr
Copy link
Contributor

cffnpwr commented Sep 27, 2022

なるほど
自環境だと再現してないのでますます謎ですね

@acid-chicken acid-chicken mentioned this issue Feb 8, 2023
@massongit
Copy link
Contributor

https://qiita.com/kawanet/items/cfedd535990b32710c50

ヒープ領域が不足している可能性があるかもしれないです。

@syuilo
Copy link
Member Author

syuilo commented Jul 9, 2023

起きなくなった気がする?

@syuilo
Copy link
Member Author

syuilo commented Oct 7, 2023

起きなくなった 🙏🏻

@syuilo syuilo closed this as completed Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠️bug? This might be a bug 🛠️Dev Development of Misskey itself 🔥high priority ❓needs more investigation A bug whose causes are unknown
Projects
None yet
Development

No branches or pull requests

7 participants