From 40ececa5a04f15610da15581ce6a4c6c5d4264ce Mon Sep 17 00:00:00 2001 From: Owen W. Taylor Date: Jun 16 2017 10:14:07 +0000 Subject: MockModuleBuilder: Fix thread safety problem with distgit-clone-wrapper Multiple build threads would try to write to the same distgit-clone-wrapper location, which could result in ETXTBSY when one thread tried to execute a script that another was writing to or vice-versa. Instead of using a wrapper script, use a sh -c invocation for distgit_get. https://pagure.io/fm-orchestrator/issue/592 --- diff --git a/module_build_service/builder/MockModuleBuilder.py b/module_build_service/builder/MockModuleBuilder.py index 42c1b57..892cedf 100644 --- a/module_build_service/builder/MockModuleBuilder.py +++ b/module_build_service/builder/MockModuleBuilder.py @@ -27,6 +27,7 @@ import os import koji import kobo.rpmlib import modulemd +import pipes import yaml import threading @@ -466,27 +467,23 @@ class SCMBuilder(BaseBuilder): distgit_get = distgit_cmds[0].format(artifact_name) # mock-scm cannot checkout particular commit hash, but only branch. - # We therefore create distgit-clone-wrapper script which clones - # the repository and checkouts particular commit hash. + # We therefore use a command that combines the distgit-command with + # checking out a particular commit hash. # See https://bugzilla.redhat.com/show_bug.cgi?id=1459437 for # more info. Once mock-scm supports this feature, we can remove # this code. - wrapper_path = os.path.join(os.path.dirname(config), "distgit-clone-wrapper") - with open(wrapper_path, "w") as fd: - fd.writelines([ - "#!/bin/sh -eu\n", - "%s\n" % distgit_get, - "git -C $1 checkout $2\n", - ]) - self._make_executable(wrapper_path) + distgit_get_branch = \ + "sh -c {}'; git -C {} checkout {}'".format(pipes.quote(distgit_get), + artifact_name, + branch) f.writelines([ "config_opts['scm'] = True\n", "config_opts['scm_opts']['method'] = 'distgit'\n", "config_opts['scm_opts']['package'] = '{}'\n".format( artifact_name), - "config_opts['scm_opts']['distgit_get'] = '{} {} {}'\n".format( - wrapper_path, artifact_name, branch), + "config_opts['scm_opts']['distgit_get'] = {!r}\n".format( + distgit_get_branch), "config_opts['scm_opts']['distgit_src_get'] = '{}'\n".format( distgit_cmds[1]), ]) diff --git a/module_build_service/config.py b/module_build_service/config.py index ebced7f..3419883 100644 --- a/module_build_service/config.py +++ b/module_build_service/config.py @@ -301,7 +301,7 @@ class Config(object): 'type': dict, 'default': { 'git://pkgs.fedoraproject.org': - ('fedpkg clone --anonymous $1', + ('fedpkg clone --anonymous {}', 'fedpkg --release module sources'), }, 'desc': 'Mapping between dist-git and command to '},