Closed feiloo closed 1 year ago
This is a hidden gotcha about Nextflow scripts. Since you declared the readfile
variable without def
, it was created as a global i.e. script variable, rather than a local variable to the closure. This causes a race condition where each invocation of the map
operator sets this variable, then reads from it in the print statement.
Basically, temp variables in a closure like this should always be declared with def
:
def readfile = file(read)
I will add a note to the documentation about it.
Indeed, thank you 👍.
Bug report
Expected behavior and actual behavior
I expect that
file(read).getName()
returns the value ofread
, but it sometimes returns the next value in the channel.It returns for example "s1r2" instead of "s1r1" in the workflow below, in about 1 of 4 runs.
Steps to reproduce the problem
commands:
contents of bug.nf:
Program output
command output (spacing edited, still incorrect in github somehow):
nextflow.log:
Environment
23.04.0.5857
openjdk 17.0.8 2023-07-18 OpenJDK Runtime Environment (build 17.0.8+0-suse-150400.3.27.1-x8664) OpenJDK 64-Bit Server VM (build 17.0.8+0-suse-150400.3.27.1-x8664, mixed mode, sharing)
openSUSE Leap 15.4
GNU bash, version 4.4.23(1)-release (x86_64-suse-linux-gnu)
Additional context