-
Notifications
You must be signed in to change notification settings - Fork 219
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
fix: TypeError occurs during export #9481
Conversation
|
@@ -349,13 +349,12 @@ class ExportService { | |||
|
|||
const output = fs.createWriteStream(zipFile); | |||
|
|||
// pipe archive data to the file | |||
const stream = pipeline(archive, output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://redmine.weseek.co.jp/issues/158989 の修正
以下のエラー内容通り、await して promise instance を渡さないように修正
@growi/app:dev: Unhandled Rejection: Promise: Promise {
@growi/app:dev: <rejected> TypeError: The "stream" argument must be an instance of ReadableStream, WritableStream, or Stream. Received an instance of Promise
@growi/app:dev: at eos (node:internal/streams/end-of-stream:74:11)
@growi/app:dev: at node:internal/streams/end-of-stream:314:21
@growi/app:dev: at new Promise (<anonymous>)
@growi/app:dev: at finished (node:internal/streams/end-of-stream:313:10)
@growi/app:dev: at ExportService.zipFiles (/workspace/growi/apps/app/src/server/service/export.js:358:11)
@growi/app:dev: at ExportService.exportCollectionsToZippedJson (/workspace/growi/apps/app/src/server/service/export.js:229:32)
@growi/app:dev: at processTicksAndRejections (node:internal/process/task_queues:95:5)
@growi/app:dev: at async ExportService.export (/workspace/growi/apps/app/src/server/service/export.js:252:21) {
@growi/app:dev: code: 'ERR_INVALID_ARG_TYPE'
@growi/app:dev: }
await finished(stream); | ||
|
||
// pipe archive data to the file | ||
await pipeline(archive, output); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://redmine.weseek.co.jp/issues/159015 の修正
バグの原因
- POST /_api/v3/export を叩き zip ファイルを作成する。exportService の以下のクラス変数に値が入る。
growi/apps/app/src/server/service/export.js
Line 247 in 6920dba
this.currentProgressingStatus = new ExportProgressingStatus(collections); - しかし try ブロックの中で実行されている処理が原因で以下の finaly ブロックが実行されない (バグの原因1で入ったデータが残り続ける)
growi/apps/app/src/server/service/export.js
Line 255 in 6920dba
this.currentProgressingStatus = null; - クライアントは GET /_api/v3/export/status を叩き export 中の処理が無いかをチェックしている。export 中の 処理がある場合は export ボタンが disabled になる。export 中の処理があるか否かは exportService の getStatus() の中で this.currentProgressingStatus が null か否かをみている。バグの原因1の時点で残り続けたデータが存在することで export 中の判定がされてしまってる。
finaly ブロックが実行されない原因
archive.finalize()
が実行される前に await pipeline(archive, output)
が実行されていたことによって archive 側の処理の終了を待つ前に pipeline() 側が完了待ちになってしまったことでこのメソッド自体が終了しなかったことが原因(158989 の修正によって await を追加したため)。
そのため archive.finalize()
が先に実行されるように修正した。pipeline を await することによって stream の完了待ちができるため await finished(stream) は不要になったので削除した。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await finished(stream); | ||
|
||
// pipe archive data to the file | ||
await pipeline(archive, output); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Task
経緯
stream/promises
package の pipeline を利用