react-native-community / cli

The React Native Community CLI - command line tools to help you build RN apps
MIT License
2.41k stars 905 forks source link

Build waits forever for config process if output does not fit in buffer #2528

Closed ivanzamanov closed 1 month ago

ivanzamanov commented 1 month ago

Environment

System: OS: macOS 15.0.1 CPU: (8) arm64 Apple M3 Memory: 65.59 MB / 16.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 20.11.1 path: /usr/local/bin/node Yarn: version: 4.5.0 path: /usr/local/bin/yarn npm: version: 9.9.3 path: /private/tmp/ci-build/builds/CsHpycHx4/0/company/frontend/company-app/node_modules/.bin/npm Watchman: version: 2024.10.07.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.15.2 path: /usr/local/bin/pod SDKs: iOS SDK: Platforms:

Description

Gradle build freezes if output from @react-native-community/cli/build/bin.js config --platform android is too large.

Fundamentally, the issue is that the gradle script expects the process to first exit and only then reads its output. However, the process cannot exit if the pipe buffer needs to be flushed and blocks forever.

Reproducible Demo

On MacOS in particular the pipe buffer is 64 KB, so making sure to exceed that size either with plenty of dependencies or "long enough" file paths reliably reproduces this. Other platforms have different buffer sizes.

cortinico commented 1 month ago

Hey @ivanzamanov I saw your PR #2529 however the logic that is running config inside React Native 0.75 is here:

https://github.com/facebook/react-native/blob/60bc3c5aed96a54416161128111ac18962fc4510/packages/gradle-plugin/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsExtension.kt#L58-L69

ivanzamanov commented 1 month ago

Hi @cortinico

We recently upgraded from 0.71 (I believe). We have an explicit inclusion of native_modules.gradle in settings.gradle, looks like it came from this template https://github.com/react-native-community/react-native-template-typescript/blob/f1d6de596a126dbbb8259588dba660d263f137b1/template/android/settings.gradle#L2

Looks like this is standard for setting up auto-linking of native modules https://github.com/react-native-community/cli/blob/main/docs/autolinking.md#platform-android

Anyhow, it looks like the particular issue only affects projects with many native modules using autolinking from the template, not ALL builds as I initially though.

cortinico commented 1 month ago

Looks like this is standard for setting up auto-linking of native modules main/docs/autolinking.md#platform-android

Yeah this has changed since 0.75 so using native_modules.gradle is effectively deprecated

ivanzamanov commented 1 month ago

I see, so the template and docs are somewhat outdated for newer versions, then.

How would you like to proceed with this issue and PR?

cortinico commented 1 month ago

I see, so the template

mmm the template should be updated: https://github.com/react-native-community/template

and docs are somewhat outdated for newer versions, then.

Do you refer to the CLI docs? If so, they should be updated yes

ivanzamanov commented 1 month ago

I believe we used the upgrade helper when upgrading the RN version. Looking at it now, we must've simply skipped removing the reference to native_modules.gradle, so the template seems correct. So it's only the docs that are misleading at this point. I'm not too sure what the current mechanism for linking native modules is, otherwise I'd be happy to help update the docs.

Anyway, I guess feel free to close this issue and I can close the PR, since this whole script appears to be deprecated.

Thanks for the help!

cortinico commented 1 month ago

So it's only the docs that are misleading at this point. I'm not too sure what the current mechanism for linking native modules is, otherwise I'd be happy to help update the docs.

Can you point me to the documentation you're referring to so I can update it?