Skip to content

Comments

BEAM-1567 hashStream should be closed in PackageUtil#createPackageAttributes()#2121

Closed
tedyu wants to merge 7 commits intoapache:masterfrom
tedyu:master
Closed

BEAM-1567 hashStream should be closed in PackageUtil#createPackageAttributes()#2121
tedyu wants to merge 7 commits intoapache:masterfrom
tedyu:master

Conversation

@tedyu
Copy link
Contributor

@tedyu tedyu commented Feb 28, 2017

Here is related code:

      OutputStream hashStream = Funnels.asOutputStream(hasher);

hashStream should be closed upon return from the method

} catch (IOException e) {
throw new RuntimeException("Package setup failure for " + source, e);
} finally {
hashStream.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe close the countingOutputStream at L109?

  • it's the outermost wrapper
  • that will ensure the hasher has received all the bytes. (even though I happen to know that the counting stream does not buffer).

} catch (IOException e) {
throw new RuntimeException("Package setup failure for " + source, e);
} finally {
if (countingOutputStream != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I had thought that with the closing at L109 we didn't need this, but I see that we still might.

Maybe instead just make a Closer up front and let it do all the work for you?

https://github.com/google/guava/wiki/ClosingResourcesExplained

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(he says, hoping that CountingOutputStream is Closeable)

@asfbot
Copy link

asfbot commented Feb 28, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/beam_PreCommit_Java_MavenInstall/7928/

Build result: FAILURE

[...truncated 665.07 KB...] at hudson.remoting.UserRequest.perform(UserRequest.java:50) at hudson.remoting.Request$2.run(Request.java:336) at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1029) at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:137) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 31 more2017-02-28T01:42:23.268 [ERROR] 2017-02-28T01:42:23.268 [ERROR] Re-run Maven using the -X switch to enable full debug logging.2017-02-28T01:42:23.268 [ERROR] 2017-02-28T01:42:23.268 [ERROR] For more information about the errors and possible solutions, please read the following articles:2017-02-28T01:42:23.268 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException2017-02-28T01:42:23.268 [ERROR] 2017-02-28T01:42:23.268 [ERROR] After correcting the problems, you can resume the build with the command2017-02-28T01:42:23.268 [ERROR] mvn -rf :beam-runners-google-cloud-dataflow-javachannel stoppedSetting status of 0441370 to FAILURE with url https://builds.apache.org/job/beam_PreCommit_Java_MavenInstall/7928/ and message: 'Build finished. 'Using context: Jenkins: Maven clean install
--none--

@asfbot
Copy link

asfbot commented Feb 28, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/beam_PreCommit_Java_MavenInstall/7929/

Build result: FAILURE

[...truncated 665.54 KB...] at hudson.remoting.UserRequest.perform(UserRequest.java:50) at hudson.remoting.Request$2.run(Request.java:336) at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1029) at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:137) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 31 more2017-02-28T01:51:04.504 [ERROR] 2017-02-28T01:51:04.504 [ERROR] Re-run Maven using the -X switch to enable full debug logging.2017-02-28T01:51:04.504 [ERROR] 2017-02-28T01:51:04.504 [ERROR] For more information about the errors and possible solutions, please read the following articles:2017-02-28T01:51:04.504 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException2017-02-28T01:51:04.504 [ERROR] 2017-02-28T01:51:04.504 [ERROR] After correcting the problems, you can resume the build with the command2017-02-28T01:51:04.504 [ERROR] mvn -rf :beam-runners-google-cloud-dataflow-javachannel stoppedSetting status of 00d2c4a to FAILURE with url https://builds.apache.org/job/beam_PreCommit_Java_MavenInstall/7929/ and message: 'Build finished. 'Using context: Jenkins: Maven clean install
--none--

@asfbot
Copy link

asfbot commented Feb 28, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/beam_PreCommit_Java_MavenInstall/7930/

Build result: FAILURE

[...truncated 665.02 KB...] at hudson.remoting.UserRequest.perform(UserRequest.java:50) at hudson.remoting.Request$2.run(Request.java:336) at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1029) at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:137) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 31 more2017-02-28T01:53:24.738 [ERROR] 2017-02-28T01:53:24.738 [ERROR] Re-run Maven using the -X switch to enable full debug logging.2017-02-28T01:53:24.738 [ERROR] 2017-02-28T01:53:24.738 [ERROR] For more information about the errors and possible solutions, please read the following articles:2017-02-28T01:53:24.739 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException2017-02-28T01:53:24.739 [ERROR] 2017-02-28T01:53:24.739 [ERROR] After correcting the problems, you can resume the build with the command2017-02-28T01:53:24.739 [ERROR] mvn -rf :beam-runners-google-cloud-dataflow-javachannel stoppedSetting status of b0f3479 to FAILURE with url https://builds.apache.org/job/beam_PreCommit_Java_MavenInstall/7930/ and message: 'Build finished. 'Using context: Jenkins: Maven clean install
--none--

@asfbot
Copy link

asfbot commented Feb 28, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/beam_PreCommit_Java_MavenInstall/7932/

Build result: FAILURE

[...truncated 665.01 KB...] at hudson.remoting.UserRequest.perform(UserRequest.java:50) at hudson.remoting.Request$2.run(Request.java:336) at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1029) at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:137) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 31 more2017-02-28T02:03:07.691 [ERROR] 2017-02-28T02:03:07.691 [ERROR] Re-run Maven using the -X switch to enable full debug logging.2017-02-28T02:03:07.691 [ERROR] 2017-02-28T02:03:07.691 [ERROR] For more information about the errors and possible solutions, please read the following articles:2017-02-28T02:03:07.691 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException2017-02-28T02:03:07.691 [ERROR] 2017-02-28T02:03:07.691 [ERROR] After correcting the problems, you can resume the build with the command2017-02-28T02:03:07.692 [ERROR] mvn -rf :beam-runners-google-cloud-dataflow-javachannel stoppedSetting status of a9ad60c to FAILURE with url https://builds.apache.org/job/beam_PreCommit_Java_MavenInstall/7932/ and message: 'Build finished. 'Using context: Jenkins: Maven clean install
--none--

@asfbot
Copy link

asfbot commented Feb 28, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/beam_PreCommit_Java_MavenInstall/7941/

Build result: FAILURE

[...truncated 664.84 KB...] at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure/home/jenkins/jenkins-slave/workspace/beam_PreCommit_Java_MavenInstall/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/util/PackageUtil.java:[126,19] unreported exception java.io.IOException; must be caught or declared to be thrown at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1029) at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:137) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 31 more2017-02-28T03:47:59.891 [ERROR] 2017-02-28T03:47:59.892 [ERROR] Re-run Maven using the -X switch to enable full debug logging.2017-02-28T03:47:59.892 [ERROR] 2017-02-28T03:47:59.892 [ERROR] For more information about the errors and possible solutions, please read the following articles:2017-02-28T03:47:59.892 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException2017-02-28T03:47:59.893 [ERROR] 2017-02-28T03:47:59.893 [ERROR] After correcting the problems, you can resume the build with the command2017-02-28T03:47:59.893 [ERROR] mvn -rf :beam-runners-google-cloud-dataflow-javachannel stoppedSetting status of b235984 to FAILURE with url https://builds.apache.org/job/beam_PreCommit_Java_MavenInstall/7941/ and message: 'Build finished. 'Using context: Jenkins: Maven clean install
--none--

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 69.131% when pulling 8d8e08c on tedyu:master into c8dfb85 on apache:master.

@asfbot
Copy link

asfbot commented Feb 28, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/beam_PreCommit_Java_MavenInstall/7947/
--none--

} finally {
try {
closer.close();
} catch (IOException ioe) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the other changes look ok, my only doubt is how to deal with this case (didn't know that Close threw IOException :S).
I will probably let Dan comment on this since this is the Dataflow runner so the ball is in google's side.

@iemejia
Copy link
Member

iemejia commented Mar 1, 2017

I wonder if we could somehow validate that the closer is doing its work correctly in the test class. Apart of this + the comment on the empty catch I think is ok. Waiting for Dan's final check.

@tedyu
Copy link
Contributor Author

tedyu commented Mar 2, 2017

Looks like Java 1.7 is required for building beam.
I switched to try-with-resources which doesn't require handling IOException.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 69.897% when pulling 6b8aef3 on tedyu:master into c8dfb85 on apache:master.

@asfbot
Copy link

asfbot commented Mar 2, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/beam_PreCommit_Java_MavenInstall/8035/
--none--

@tedyu
Copy link
Contributor Author

tedyu commented Mar 2, 2017

@dhalperi
Which version do you prefer ?

Thanks

@iemejia
Copy link
Member

iemejia commented Mar 2, 2017

try/close is much better and is used all around the project, I think you can go ahead. WDYT Dan ?

@asfgit asfgit closed this in b322a5d Mar 2, 2017
String stagingPath, @Nullable String overridePackageName) {
try {
Closer closer = Closer.create();
boolean directory = source.isDirectory();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to un-indent here.

Hasher hasher = Hashing.md5().newHasher();
OutputStream hashStream = Funnels.asOutputStream(hasher);
try (CountingOutputStream countingOutputStream = new CountingOutputStream(hashStream)) {
closer.register(countingOutputStream);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with these changes, which are great (thanks @iemejia !), the closer no longer does anything so we can drop it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still "need" the flush at L110, so that we guarantee the hasher has seen all bytes.

@dhalperi
Copy link
Contributor

dhalperi commented Mar 2, 2017

Since the three changes were trivial, and I've been the bottleneck, I went ahead and implemented them in the merge process. Thanks @tedyu -- this is awesome.

Thanks @iemejia for dramatically improving over my review.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants