mozilla / apk-factory-service

Web service which converts Open Web Apps into native Android apps
42 stars 18 forks source link

Service should gracefully handle concurrent requests for the same manifest #8

Closed ozten closed 10 years ago

ozten commented 10 years ago

I've got a load test going. If it hit the same manifest as inputs with several concurrent requests, I get about a 20% failure rate with errors that look like various ant tasks stepping on each other's file system.

Example exceptions:

Building com.testmanifest.deltron3030-1.0.apk (10000) from http://deltron3030.testmanifest.com/manifest.webapp
{ [Error: Command failed:
BUILD FAILED
/tmp/tools/android-sdk-linux/tools/ant/build.xml:1160: The following error occurred while executing this line:
/tmp/tools/android-sdk-linux/tools/ant/build.xml:372: The following error occurred while executing this line:
/tmp/tools/android-sdk-linux/tools/ant/build.xml:364: java.io.FileNotFoundException: /tmp/android-projects/com.testmanifest.deltron3030/bin/build.prop (No such file or directory)

Total time: 14 seconds
] killed: false, code: 1, signal: null }

another pattern is a stacktrace (the missing file varies)

{ [Error: Command failed:
BUILD FAILED
/tmp/tools/android-sdk-linux/tools/ant/build.xml:962: The following error occurred while executing this line:
/tmp/tools/android-sdk-linux/tools/ant/build.xml:973: The following error occurred while executing this line:
/tmp/tools/android-sdk-linux/tools/ant/build.xml:313: com.android.sdklib.build.ApkCreationException: Failed to create '/tmp/android-projects/com.testmanifest.deltron3030/bin/TestAppdeltron3030-release-unsigned.apks': No such file or directory
    at com.android.sdklib.build.ApkBuilder.checkOutputFile(ApkBuilder.java:912)
    at com.android.sdklib.build.ApkBuilder.init(ApkBuilder.java:437)
    at com.android.sdklib.build.ApkBuilder.<init>(ApkBuilder.java:396)
    at com.android.ant.ApkBuilderTask.execute(ApkBuilderTask.java:334)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at com.android.ant.IfElseTask.execute(IfElseTask.java:124)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at com.android.ant.IfElseTask.execute(IfElseTask.java:124)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:809)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 11 seconds
] killed: false, code: 1, signal: null }
ozten commented 10 years ago

A couple ways to fix this, open to more ideas:

1) Have ant work in a uniquely named directory 2) Have the coordinator code block on a queue by manifest url, so that we're never building the same APK concurrently.

2 is fairly sane, since we'd only want to build once and let the 2nd request use the file cache.