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

Embedded mongo not working on M1 macbook: Bad CPU #494

Open
KasperWolsink99 opened this issue Nov 6, 2023 · 9 comments
Open

Embedded mongo not working on M1 macbook: Bad CPU #494

KasperWolsink99 opened this issue Nov 6, 2023 · 9 comments
Assignees

Comments

@KasperWolsink99
Copy link

KasperWolsink99 commented Nov 6, 2023

I have some issues getting Flapdoodle to work on my machine.

Im using a spring boot application and whenever I try to start an embedded mongo instance, I get this stack trace:

Caused by: java.lang.RuntimeException: could not start process - Platform{operatingSystem=OS_X, architecture=ARM_64}
	at de.flapdoodle.embed.mongo.transitions.MongoServerStarter.result(MongoServerStarter.java:129)
	at de.flapdoodle.reverse.TransitionWalker.resolve(TransitionWalker.java:58)
	at de.flapdoodle.reverse.TransitionWalker.resolve(TransitionWalker.java:46)
	at de.flapdoodle.reverse.TransitionWalker.initState(TransitionWalker.java:176)
	... 164 more
Caused by: java.io.IOException: Cannot run program "/Users/<user>/.embedmongo/fileSets/75f255a9a3917075d50c1da18ca4d30fbc1f9d1148349e1bb0544af13824da69/mongod" (in directory "/var/folders/kk/38mf3xqx0db2xlxvs28dcvfr0000gn/T/temp--05d7cfb0-da04-4007-900f-07b667b9ca81/workingDir6533170739844807501"): error=86, Bad CPU type in executable
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1170)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1089)
	at de.flapdoodle.embed.process.runtime.ProcessControl.start(ProcessControl.java:177)
	at de.flapdoodle.embed.process.types.RunningProcess.start(RunningProcess.java:76)
	at de.flapdoodle.embed.mongo.transitions.MongoServerStarter.result(MongoServerStarter.java:119)
	... 167 more
Caused by: java.io.IOException: error=86, Bad CPU type in executable
	at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
	at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:295)
	at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:225)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1126)

flapdoodle version: 4.10.0
mongodb-community version: 6.0.6
jdk version: Openjdk 17
Macbook air with apple M1
OS version: Sonoma 14.0

Im more than happy to supply any additional information if needed.

@michaelmosmann
Copy link
Member

@KasperWolsink99 can you execute /Users//.embedmongo/fileSets/75f255a9a3917075d50c1da18ca4d30fbc1f9d1148349e1bb0544af13824da69/mongod by yourself?

@KasperWolsink99
Copy link
Author

@KasperWolsink99 can you execute /Users//.embedmongo/fileSets/75f255a9a3917075d50c1da18ca4d30fbc1f9d1148349e1bb0544af13824da69/mongod by yourself?

Yes this seems to be working fine

@michaelmosmann
Copy link
Member

@KasperWolsink99 As i do not own a m1-apple i can only guess.. is the openjdk for the m1 cpu?
see https://www.digitalocean.com/community/tutorials/bad-cpu-type-in-executable-fixed

@KasperWolsink99
Copy link
Author

KasperWolsink99 commented Nov 7, 2023

@KasperWolsink99 As i do not own a m1-apple i can only guess.. is the openjdk for the m1 cpu? see https://www.digitalocean.com/community/tutorials/bad-cpu-type-in-executable-fixed

I tried running it with the Zulu JVM but the error still persisted. However, I did end up finding a solution.

The mongod binary is a x86 executable:

file mongod

mongod: Mach-O 64-bit executable x86_64

The mongod instance installed through homebrew was an arm based executable.
I replaced the mongod and mongoimport binaries flapdoodle uses with the ARM ones and to my surprise this actually worked :).

It is a bit hacky but for my use-case it is sufficient. Thanks for the help!

@michaelmosmann
Copy link
Member

@KasperWolsink99 .. hmm.. this is strange. There should be an arm-version for 6.0.6 (see https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.packageresolver/blob/4b0ca475ecc54f75b2bdde1bf88e059f73622bb1/src/main/java/de/flapdoodle/embed/mongo/packageresolver/OSXPackageFinder.java#L80) .. do you have any log information/stack trace? Maybe there is a hint there..

@KasperWolsink99
Copy link
Author

@michaelmosmann it is worth pointing out that my colleagues also have a M1 mac and they did not encounter this exact problem. What is really interesting though is that their mongo executables used by flapdoodle were also x86 executables. Maybe the reason it worked for them is because they have Rosetta configured differently? I am actually not sure but it might be worth it to confirm this with someone else on an ARM based mac.

The complete stack trace (left out spring specific stuff):

Caused by: java.lang.RuntimeException: rollback after error on transition to State(de.flapdoodle.embed.mongo.transitions.RunningMongodProcess), successful reached:
  StateID{name=, type=class de.flapdoodle.embed.process.archives.ExtractedFileSet}=ExtractedFileSet{baseDir=/Users/<user>/.embedmongo/fileSets/75f255a9a3917075d50c1da18ca4d30fbc1f9d1148349e1bb0544af13824da69, executable=/Users/<user>/.embedmongo/fileSets/75f255a9a3917075d50c1da18ca4d30fbc1f9d1148349e1bb0544af13824da69/mongod, libraryFiles=[]},
  StateID{name=, type=class de.flapdoodle.embed.process.types.Archive}=Archive(/Users/<user>/.embedmongo/archives/https-fastdl-mongodb-org/56cb3d10404e5b9df5358ac4ee83efcb/osxmongodb-macos-x86-64-4-4-18-tgz/8636c64a86ffa7d89112ce6321f91be6cf93df2519c5deca45b64d61e6cf7617/archive.tgz),
  StateID{name=, type=interface de.flapdoodle.embed.process.store.DownloadCache}=de.flapdoodle.embed.process.store.LocalDownloadCache@13234ac9,
  StateID{name=, type=interface de.flapdoodle.embed.process.config.store.Package}=Package{archiveType=TGZ, fileSet=FileSet{entries=[Entry{type=Executable, destination=mongod, uncompiledMatchingPattern=UncompiledPattern{regex=.*mongod, flags=2}}]}, url=https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.18.tgz},
  StateID{name=, type=interface de.flapdoodle.embed.process.store.ExtractedFileSetStore}=de.flapdoodle.embed.process.store.ContentHashExtractedFileSetStore@7254838,
  StateID{name=, type=class de.flapdoodle.embed.process.types.ProcessArguments}=ProcessArguments([--dbpath, /var/folders/kk/38mf3xqx0db2xlxvs28dcvfr0000gn/T/temp--95054139-ca4b-44f5-9735-f3230cfb53ab/mongod-database1617292266983625110, --noauth, --nojournal, --port, 49598, --syncdelay=0]),
  StateID{name=, type=class de.flapdoodle.embed.process.types.ProcessWorkingDir}=ProcessWorkingDir(/var/folders/kk/38mf3xqx0db2xlxvs28dcvfr0000gn/T/temp--95054139-ca4b-44f5-9735-f3230cfb53ab/workingDir6662374873165461478),
  StateID{name=, type=class de.flapdoodle.embed.process.distribution.Distribution}=V4_4:Platform{operatingSystem=OS_X, architecture=ARM_64},
  StateID{name=, type=interface de.flapdoodle.embed.process.config.SupportConfig}=SupportConfig{name=mongod, supportUrl=https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/issues, messageOnException=de.flapdoodle.embed.mongo.transitions.ProcessDefaults$$Lambda$915/0x0000000301551f00@39374689},
  StateID{name=, type=class de.flapdoodle.embed.process.types.Name}=Name(mongod),
  StateID{name=, type=class de.flapdoodle.embed.process.io.directories.PersistentDir}=ImmutablePersistentDir(/Users/<user>/.embedmongo),
  StateID{name=, type=class de.flapdoodle.embed.mongo.types.DatabaseDir}=DatabaseDir(/var/folders/kk/38mf3xqx0db2xlxvs28dcvfr0000gn/T/temp--95054139-ca4b-44f5-9735-f3230cfb53ab/mongod-database1617292266983625110),
  StateID{name=, type=class de.flapdoodle.embed.process.io.directories.TempDir}=ImmutableTempDir(/var/folders/kk/38mf3xqx0db2xlxvs28dcvfr0000gn/T/temp--95054139-ca4b-44f5-9735-f3230cfb53ab),
  StateID{name=, type=class de.flapdoodle.embed.mongo.types.DistributionBaseUrl}=DistributionBaseUrl(https://fastdl.mongodb.org),
  StateID{name=, type=class de.flapdoodle.os.Platform}=Platform{operatingSystem=OS_X, architecture=ARM_64},
  StateID{name=, type=interface de.flapdoodle.embed.process.types.ProcessConfig}=ProcessConfig{daemonProcess=false, stopTimeoutInMillis=5000},
  StateID{name=, type=class de.flapdoodle.embed.process.types.ProcessEnv}=ProcessEnv({}),
  StateID{name=, type=interface de.flapdoodle.embed.process.io.ProcessOutput}=ProcessOutput{output=de.flapdoodle.embed.process.io.Slf4jStreamProcessor@2e204155, error=de.flapdoodle.embed.process.io.Slf4jStreamProcessor@27dc335a, commands=de.flapdoodle.embed.process.io.NamedOutputStreamProcessor@a95cb11},
  StateID{name=, type=class de.flapdoodle.embed.mongo.types.SystemEnv}=SystemEnv({PATH=/Users/<user>/.jenv/shims:/Users/<user>/.jenv/bin:/Users/<user>/.nvm/versions/node/v18.16.1/bin:/Users/<user>/IdeaProjects/scripts/local/deployment:/Users/<user>/IdeaProjects/scripts/sql/execution:/Users/<user>/IdeaProjects/scripts/ops:/Users/<user>/IdeaProjects/scripts/nas:/Users/<user>/IdeaProjects/scripts/crunch:/Users/<user>/IdeaProjects/scripts/local:/Users/<user>/IdeaProjects/scripts/MyProject:/Users/<user>/IdeaProjects/scripts/gcp:/Users/<user>/IdeaProjects/scripts/api:/Users/<user>/IdeaProjects/scripts/utilityscripts:/Users/<user>/IdeaProjects/scripts/functions:/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3/bin:/opt/homebrew/opt/openjdk@11/bin:/Users/<user>/google-cloud-sdk/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin, MANPATH=/Users/<user>/.nvm/versions/node/v18.16.1/share/man:/opt/homebrew/share/man::, JENV_FORCEJDKHOME=true, JAVA_HOME=/Users/<user>/.jenv/versions/zulu64-17.0.9, JAVA_MAIN_CLASS_41399=com.intellij.rt.junit.JUnitStarter, HOMEBREW_PREFIX=/opt/homebrew, COMMAND_MODE=unix2003, MAVEN_OPTS=--add-opens java.base/java.time=ALL-UNNAMED, NVM_INC=/Users/<user>/.nvm/versions/node/v18.16.1/include/node, LOGNAME=<user>, JDK_HOME=/Users/<user>/.jenv/versions/zulu64-17.0.9, HOMEBREW_REPOSITORY=/opt/homebrew, PWD=/Users/<user>/IdeaProjects/MyProject, XPC_SERVICE_NAME=application.com.jetbrains.intellij.3491381.10104629, INFOPATH=/opt/homebrew/share/info:, __CFBundleIdentifier=com.jetbrains.intellij, NVM_CD_FLAGS=-q, NVM_DIR=/Users/<user>/.nvm, SHELL=/bin/zsh, HOMEBREW_CELLAR=/opt/homebrew/Cellar, OLDPWD=/, USER=<user>, JENV_FORCEJAVAHOME=true, TMPDIR=/var/folders/kk/38mf3xqx0db2xlxvs28dcvfr0000gn/T/, SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.EVOCSiUX5V/Listeners, XPC_FLAGS=0x0, __CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0, LC_CTYPE=en_NL.UTF-8, JENV_SHELL=zsh, NVM_BIN=/Users/<user>/.nvm/versions/node/v18.16.1/bin, HOME=/Users/<user>, JENV_LOADED=1}),
  StateID{name=, type=interface de.flapdoodle.embed.process.io.progress.ProgressListener}=de.flapdoodle.embed.process.io.progress.StandardConsoleProgressListener@915d7c4,
  StateID{name=, type=class de.flapdoodle.embed.mongo.packageresolver.Command}=MongoD,
  StateID{name=, type=interface de.flapdoodle.embed.process.distribution.Version}=V4_4,
  StateID{name=, type=class de.flapdoodle.embed.mongo.config.Net}=Net{port=49598, isIpv6=false},
  StateID{name=, type=class de.flapdoodle.embed.mongo.commands.MongodArguments}=MongodArguments{syncDelay=0, useDefaultSyncDelay=false, isVerbose=false, verbosityLevel=1, isQuiet=false, useNoPrealloc=true, useSmallFiles=true, useNoJournal=true, enableTextSearch=false, auth=false, master=false, isConfigServer=false, isShardServer=false, params={}, args={}}

	at de.flapdoodle.reverse.TransitionWalker.initState(TransitionWalker.java:186)
	at de.flapdoodle.reverse.TransitionWalker.initState(TransitionWalker.java:65)
	at MyProject.database.MongoEmbeddedConfig.startMongoEmbedded(MongoEmbeddedConfig.java:58)
	at MyProject.database.MongoEmbeddedConfig.mongoDatabase(MongoEmbeddedConfig.java:40)
	at MyProject.database.MongoEmbeddedConfig$$SpringCGLIB$$0.CGLIB$mongoDatabase$0(<generated>)
	at MyProject.database.MongoEmbeddedConfig$$SpringCGLIB$$FastClass$$1.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
	at MyProject.database.MongoEmbeddedConfig$$SpringCGLIB$$0.mongoDatabase(<generated>)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:139)
	... 153 more
Caused by: java.lang.RuntimeException: could not start process - Platform{operatingSystem=OS_X, architecture=ARM_64}
	at de.flapdoodle.embed.mongo.transitions.MongoServerStarter.result(MongoServerStarter.java:129)
	at de.flapdoodle.reverse.TransitionWalker.resolve(TransitionWalker.java:58)
	at de.flapdoodle.reverse.TransitionWalker.resolve(TransitionWalker.java:46)
	at de.flapdoodle.reverse.TransitionWalker.initState(TransitionWalker.java:176)
	... 166 more
Caused by: java.io.IOException: Cannot run program "/Users/<user>/.embedmongo/fileSets/75f255a9a3917075d50c1da18ca4d30fbc1f9d1148349e1bb0544af13824da69/mongod" (in directory "/var/folders/kk/38mf3xqx0db2xlxvs28dcvfr0000gn/T/temp--95054139-ca4b-44f5-9735-f3230cfb53ab/workingDir6662374873165461478"): error=86, Bad CPU type in executable
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
	at de.flapdoodle.embed.process.runtime.ProcessControl.start(ProcessControl.java:177)
	at de.flapdoodle.embed.process.types.RunningProcess.start(RunningProcess.java:76)
	at de.flapdoodle.embed.mongo.transitions.MongoServerStarter.result(MongoServerStarter.java:119)
	... 169 more
Caused by: java.io.IOException: error=86, Bad CPU type in executable
	at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
	at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:314)
	at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:244)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)
	... 173 more

@michaelmosmann
Copy link
Member

@KasperWolsink99 are there any updates on this issue?

@KasperWolsink99
Copy link
Author

@michaelmosmann not really aside from the latest stacktrace I posted.

@mistvan
Copy link

mistvan commented Mar 1, 2024

I just installed rosetta 2 on your mac using softwareupdate --install-rosetta. It added support for running embedded mongo simulating required architecture.

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

No branches or pull requests

3 participants