# Node-Red stopping process to early

**URL:** <https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433>\
**Category:** General\
**Created:** [28 March 2022 07:06 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433 "2022-03-28T07:06:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [28 March 2022 07:06 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/1 "2022-03-28T07:06:33Z")

</div>

Hi!

I'm struggling with the following:

I'm using NR to get a csv from a FTP server, run a java program via exec (using command "ant") and then transfer the output file to another FTP.

When I run ant directly via ssh on the server, the complete file with about 500.000 rows gets exported, taking about 18 seconds.  
On the other hand, if I run "ant" via NR, it only takes 3 seconds but also only exports 90.000 to 150.000 rows.

Why is there a difference?  
It runs the exact same files.

These are my settings in the node:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/6/5633a7370b70cdbce2e32f7b6f58f53459c19ba4.png)

Thank you very much for your support.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 March 2022 08:42 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/2 "2022-03-28T08:42:41Z")

</div>

What do you see on the three outputs from the exec node? Use (named) debug nodes set to show complete message.

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [28 March 2022 08:56 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/3 "2022-03-28T08:56:01Z")

</div>

stdout provides:

```auto
Buildfile: /root/transfer/stock/build.xml

compile:
    [javac] Warning: *******.csv modified in the future.

test:
     [java] Mapping Application
     [java] Parsing Text...
     [java] 
     [java] Finished

BUILD SUCCESSFUL
Total time: 1 second

```

stderr no output

return code:

```auto
{"code":0}

```

I also get the "modified in the future" error via cli

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 March 2022 09:10 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/4 "2022-03-28T09:10:49Z")

</div>

What does your script actually do, it appears to be building the app and then exiting, rather than running it.

When you run the command in a terminal what output to you see, and how long does it take before it returns to the command prompt? I am wondering whether the script builds the app and then spawns a process to run it, but does not wait for it to complete before returning.

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [28 March 2022 09:31 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/5 "2022-03-28T09:31:17Z")

</div>

Prior to the command "ant" I ran "ant clean jar", which is only necessary one time.

Now, it's sufficient to run "ant" which just runs the program. The program itself is a java program, generated from a third party flow processor.  
It takes a csv as input, does some converting and puts out another csv.

Output in terminal is:

```auto
Picked up _JAVA_OPTIONS: -Xmx5120m
Buildfile: /root/transfer/stock/build.xml

compile:

test:
     [java] Picked up _JAVA_OPTIONS: -Xmx5120m
     [java] Mapping Application
     [java] Parsing Text...
     [java]
     [java] Finished

BUILD SUCCESSFUL
Total time: 14 seconds

```

But yeah, now I see a difference there. Running it from terminal says that it picked up the java option -Xmx5120m which is set under /etc/profile.  
Maybe I have to set this in any other location to have it system wide?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 March 2022 09:36 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/6 "2022-03-28T09:36:54Z")

</div>

If that is an environment option then you should be able to set it in the command in the exec node. Something like  
`cd /root/transfer/stock && _JAVA_OPTIONS=-Xmx5120 ant`

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [28 March 2022 10:12 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/7 "2022-03-28T10:12:20Z")

</div>

Well it picks up the option, but still only takes about 3-4 seconds and not all rows are exported:

```auto
Buildfile: /root/transfer/stock/build.xml

compile:
    [javac] Warning: *****.csv modified in the future.

test:
     [java] Picked up _JAVA_OPTIONS: -Xmx5120m
     [java] Mapping Application
     [java] Parsing Text...
     [java] 
     [java] Finished

BUILD SUCCESSFUL
Total time: 3 seconds

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 March 2022 10:17 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/8 "2022-03-28T10:17:07Z")

</div>

> [@smitterer](#):
>
> `[javac] Warning: *****.csv modified in the future.`

What is that file? It suggests that your system time is confused or something like that. Is node-red running in docker? If so then check that the docker time and timezone are the same as the system.

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [28 March 2022 10:34 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/9 "2022-03-28T10:34:52Z")

</div>

I also get this error while running via terminal.

I forgot to remove the name of the file. Did so now. Would you mind doing so also in your reply? Thanks

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 March 2022 10:42 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/10 "2022-03-28T10:42:18Z")

</div>

Done. The terminal o/p you showed from the terminal did not show that line, or had you deleted the line? I would still like to know what the file is, as it appears to be part of the compile sequence.

You could try the exec node in Spawn mode. I still suspect it is something to do with the script launching another process, which is then getting killed off early.

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [28 March 2022 11:28 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/11 "2022-03-28T11:28:42Z")

</div>

Yes starting it via terminal also gives the warning about the date in future.

The file is a file provided by our supplier with some product data. The java process takes some of the columns, filters some rows and the puts out another file.

Spawn mode results in return code saying code: -2

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 March 2022 12:34 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/12 "2022-03-28T12:34:42Z")

</div>

> [@smitterer](#):
>
> The file is a file provided by our supplier with some product data.

Why is that appearing under a compile heading? I thought they were coming from Java, building the app. Or does all that output come from the application itself? If from the application, can you add some debug to it to try and work out what is happeining?

> [@smitterer](#):
>
> Spawn mode results in return code saying code: -2

That is presumably from output 3. What about outputs 1 and 2? Set the debug nodes to show Complete Message and show us what they all give.

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [29 March 2022 06:20 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/13 "2022-03-29T06:20:08Z")

</div>

As it is saying "Parsing Text", I guess this is part of the java app, not from the compiling.

Output 1 and 2 unfortunately don't put out anything when in spawn mode.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 March 2022 08:25 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/14 "2022-03-29T08:25:29Z")

</div>

> [@smitterer](#):
>
> As it is saying "Parsing Text", I guess this is part of the java app, not from the compiling.

The error appears under the Compiling. Also the option -Xmx5120 is an instruction about how much heap to allocate, so I would have thought that line would be before it actually starts running the app.  
Also a but of googling suggests that the three seconds is the time taken to build it, not to run it.

What exactly is the file `ant`? Is it a shell script of some sort? If so then what is in it.

> [@smitterer](#):
>
> Output 1 and 2 unfortunately don't put out anything when in spawn mode.

What, no message at all?  
Did you wait some time to make sure nothing is going to arrive?  
Did it convert any records?  
Did the message on o/p 3 arrive instantly?  
Are you sure you changed nothing except the spawn mode?

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [29 March 2022 08:54 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/15 "2022-03-29T08:54:55Z")

</div>

I'm not an expert by any means in ant but from what I understand is, that it is used to compile and then run java-based programs. So first, you do something like "ant clean jar" to compile it. From that moment on, you just have to do "ant" to run it.

The program is already compiled and therefore, we only need ant to trigger the program, while this just runs some conversion.

In spawn mode, I only have an output in "return code" and none for the others. In exec mode, all outputs provide something. Nothing else changed.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 March 2022 09:45 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/16 "2022-03-29T09:45:00Z")

</div>

OK, I have no idea why it does not run in spawn mode.

Create a file in the directory called `antrun.sh` (or whatever you fancy), containing this script

```auto
#!/usr/bin/env sh
# run ant and wait 30 seconds
echo "running ant"
_JAVA_OPTIONS=-Xmx5120 ant
echo "ant completed, waiting 30 seconds"
sleep 30
echo "done"

```

Make it executable, then in the exec node put  
`cd /root/transfer/stock && _JAVA_OPTIONS=-Xmx5120 /root/transfer/stock/antrun.sh`  
The above is all one line of course. Set the exec node to Exec mode.

That should run ant exactly as before, but will wait 30 seconds before terminating, so if my supposition that the app is running in the background, and it is the shell termination that stops it is correct, then you should get all your data converted. If it works then there is probably a better way of solving it.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 March 2022 10:37 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/17 "2022-03-29T10:37:46Z")

</div>

Another thought, what version of node-red (at bottom of editor menu), and nodejs (command `node -v`) are you using? I seem to remember a fix a long time ago that was causing the exec node to terminate early in the case where the command spawned further tasks.

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [29 March 2022 10:41 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/18 "2022-03-29T10:41:39Z")

</div>

So after adding "m" at the end of -Xmx5120 it ran (before it threw an error) but it only exported about 44.500 rows.

Outputs:

```auto
running ant
Buildfile: /root/transfer/stock/build.xml

compile:
    [javac] Warning: *******.csv modified in the future.

test:
     [java] Picked up _JAVA_OPTIONS: -Xmx5120m
     [java] Mapping Application
     [java] Parsing Text...
     [java] 
     [java] Finished

BUILD SUCCESSFUL
Total time: 7 seconds
ant completed, waiting 30 seconds
done

```

```auto
Picked up _JAVA_OPTIONS: -Xmx5120m

```

```auto
{"code":0}

```

Versions:  
Node-Red: 2.2.2  
nodejs: 14.19.1

Thanks for your support!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 March 2022 10:49 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/19 "2022-03-29T10:49:25Z")

</div>

Assuming that it waited the 30 seconds then I am all out of ideas, other than to add some debug into the app in order to determine what is going wrong.

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [29 March 2022 10:52 UTC](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433/20 "2022-03-29T10:52:30Z")

</div>

Might it be connected to some user problems?

Maybe some user specific restrictions?

[Next page](https://discourse.nodered.org/t/node-red-stopping-process-to-early/60433.md?page=2)
