[ZBX-24799] Cannot execute script. timeout while retrieving result for remote command Created: 2024 Jul 06  Updated: 2025 Aug 20

Status: Needs documenting
Project: ZABBIX BUGS AND ISSUES
Component/s: Documentation (D), Server (S)
Affects Version/s: 7.0.0
Fix Version/s: 7.0.18rc1, 7.2.12rc1, 7.4.2rc1, 8.0.0alpha1 (master)

Type: Problem report Priority: Trivial
Reporter: Markku Leiniö Assignee: Martins Valkovskis
Resolution: Unresolved Votes: 17
Labels: None
Remaining Estimate: Not Specified
Time Spent: 7h
Original Estimate: Not Specified
Environment:

Zabbix server 7.0.0
Zabbix proxy 7.0.0
Zabbix agent 7.0.0 on Linux


Attachments: PNG File image-2024-07-06-20-49-58-145.png     File supportcase-2024-07-06.pcap    
Issue Links:
Duplicate
is duplicated by ZBX-24823 Unable to Execute Scripts/Commands fr... Closed
Related
related to ZBX-26510 Zabbix Agent active remote command ex... IN DOCUMENTING
Team: Team A
Sprint: Documentation backlog
Story Points: 1

 Description   

Steps to reproduce:

  1. Have an active agent configured and working with agent interface address 127.0.0.1
  2. Set AllowKey=system.run[*] in the agent
  3. In Zabbix UI, go to Alerts - Scripts and create a script:
    1. Name: Hostname script
    2. Scope: Manual host action
    3. Type: Script
    4. Execute on: Zabbix agent
    5. Commands: hostname
  4. Go to Administration - General - Timeouts, set the Script timeout to 10s
  5. Go to Monitoring - Hosts, click on the agent host and run "Hostname script"
  6. Observe the results

Result:

Sometimes the script runs successfully. But most often the result is:

Cannot execute script. timeout while retrieving result for remote command

Expected:

Successful script execution is expected all the time.

 

Packet analysis based on the attachment "supportcase-2024-07-06.pcap":

  • At 20:33:38 (frames 19-20) the proxy connects to the server and receives plain "success" as response (= no remote commands to execute anywhere)
  • At 20:33:39 (frames 25-26) the proxy connects to the server and receives the command to execute on the agent (taskid 74)
  • At 20:33:44 (frames 35-36) the agent connects to the proxy and receives the command "hostname" to execute
  • At 20:33:44 (frames 37-38) the agent has executed the command and returned the result "ubuntutest2204" to the proxy, with result "success"
  • Right after that at 20:33:44 (frames 39-40) the proxy sends the taskid 74 results to the server as "timeout while retrieving result for remote command"

--> Why does the proxy say "timeout" to the server even though the agent returned the response?



 Comments   
Comment by Markku Leiniö [ 2024 Jul 06 ]

I have to comment that while writing this I tried the remote command numerous times and I haven't got the result shown successfully even once.

But earlier today I saw the hostname command result successfully in the UI at least at two occasions, not sure how those cases were different.

Comment by Liang Weide [ 2024 Jul 16 ]

I reproduce this with Zabbix agent2 7.0.0 on windows11.

Also, as document say that active agent would get items from server every 2 mins. I try to adjust Script timeout to 150s, can not help. Then I notice that after few minutes after I click on the agent host and run "Hostname script" (the error message would show and I can close it), the agent2 on windows11 was down.

The finnal log of agent2 is below. The agent2 is stop without error and stop message, which really confused

2024/07/16 21:39:30.192277 [SystemRun] Executing command:'D:\miniconda\python.exe E:\REST-Voyager\stop_try.py'
Comment by Markku Leiniö [ 2024 Jul 18 ]

Agent 7.0.0 connects to proxy/server every 5 seconds as the documentation says: https://www.zabbix.com/documentation/current/en/manual/appendix/config/zabbix_agent2_win#refreshactivechecks

Agent stopping is said to be fixed in 7.0.1: ZBX-24719

 

Comment by Markku Leiniö [ 2024 Aug 08 ]

sasha maybe this one needs review as well?

 

Edit: sorry, didn't notice that you already have reviewed this last week against some internal ticket

Comment by Alexander Vladishev [ 2024 Aug 14 ]

Hi!

I was able to reproduce this issue by artificially increasing the script execution time by adding the command sleep 3.

When executing scripts, a timeout is used that is specified in the proxy/server configuration file. Try increasing the value of this parameter if it is set too low.

You can also see this timeout in the agent's log file (with DebugLevel=4):

768777:20240814:053325.406 Requested [{"request":"passive checks","data":[{"key":"system.run[hostname]","timeout":4}]}]
768777:20240814:053325.406 Executing command 'hostname'
768777:20240814:053325.407 In zbx_popen() command:'hostname'
768777:20240814:053325.408 End of zbx_popen():6
768891:20240814:053325.409 zbx_popen(): executing script
768777:20240814:053325.414 In zbx_waitpid()
768777:20240814:053325.414 zbx_waitpid() exited, status:0
768777:20240814:053325.414 End of zbx_waitpid():768891
768777:20240814:053325.414 execute_str_local() command:'hostname' len:6 cmd_result:'ubuntu'
768777:20240814:053325.414 Sending back [{"version":"7.0.0","variant":1,"data":[{"value":"ubuntu"}]}] 

In Administration -> General -> Timeouts -> Network timeouts for UI -> Script execution, you can set the timeout for the entire script execution chain:
1. UI -> Server
2. Server -> Proxy
3. Proxy -> Agent
4. Agent -> Proxy
5. Proxy -> Server
6. Server -> UI

Comment by Markku Leiniö [ 2024 Aug 14 ]

In the issue the configured timeouts were not reached:

  • Global Script timeout = 10s (script execution on the agent took less than a second)
  • Network timeout for Script execution = 60s
  • Total time from server sending the script execution request to proxy to proxy sending the response to server was under 6 seconds
Comment by Alexander Vladishev [ 2024 Aug 14 ]

What is the value of the Timeout parameter in your proxy configuration file?

Comment by Markku Leiniö [ 2024 Aug 14 ]

The default as supplied by the installer: Timeout=4

That's the connect timeout from proxy process to server trapper, since 7.0, right? Not any kind of item timeout anymore.

Comment by Markku Leiniö [ 2024 Aug 14 ]

I tested this again with 7.0.2 components:

  • 14:18:23 script execution clicked on UI
  • 14:18:24.9 server responded to active proxy data request with the remote command to execute on agent
  • 14:18:25.1 agent requested active checks from proxy, proxy didn't say anything about commands to execute
  • 14:18:29.9 proxy sent task data to server: "timeout while retrieving result for remote command"
  • 14:18:30.1 agent next time requested active check from proxy, nothing to say about remove commands anymore

I don't see 10s (script timeout) having elapsed yet.

 

Comment by Markku Leiniö [ 2024 Aug 14 ]

Another example, this time script timeout = 20s:

  • 14:50:55 script execution clicked on UI
  • 14:50:56.5 server responded to active proxy data request with the remote command to execute on agent
  • 14:51:00.0 agent requested active checks from proxy, proxy didn't say anything about commands to execute
  • 14:51:04.5 proxy sent task data to server: "timeout while retrieving result for remote command"
  • 14:51:05.0 agent next time requested active check from proxy, nothing to say about remove commands anymore

Again, no 20s timeout yet. But, in the previous example (script timeout = 10s) it took 5 seconds for proxy to declare timeout, in this example (script timeout = 20s) it took 8 seconds for proxy to declare timeout.

Note: I also see successful executions, I'm just pointing out that the executions are really unreliable.

Example of a successful command:

  • 14:50:07 script execution clicked on UI
  • 14:50:08.4 server responded to active proxy data request with the remote command to execute on agent
  • 14:50:11.0 agent requested active checks from proxy, proxy gave the command "hostname" to execute:
     
    {"response":"success","commands":[{"command":"hostname","id":4,"wait":1,"timeout":4}]} 

     

  • 14:50:11.0 (two milliseconds later) agent sent the result to proxy, proxy said "success"
  • 14:50:11.4 proxy sent data to server, nothing about the task result
  • 14:50:12.4 proxy sent task data to server (the hostname the agent sent, OK)

(Irrelevant for this particular issue, but from where is that "timeout":4 (the command timeout given by proxy to agent) value coming from? Proxy Timeout=4 configuration directive?)

Comment by Andrew A [ 2024 Aug 14 ]

I am having the same issue, and in some cases even very simple scripts are timing out even when the agent log shows the data being successfully returned.

In zabbix_server.conf, I set Timeout=30 and now my scripts are either successful or it takes approximately 30 seconds before I get an error.

So it seems like some of timeout settings configurable in the GUI are still limited by the settings in the conf file.

I haven't tested with a proxy but it's probably a similar issue.

Comment by Alexander Vladishev [ 2024 Aug 15 ]

If you are running scripts on active agents, the RefreshActiveChecks parameter in the agent's configuration file should be set to a value lower than the Timeout in the server or proxy configuration file (depending on where the agent is connected).

The active agent receives the list of scripts to be executed along with the list of active checks.

How often does your agent request the list of active checks?

Comment by Alexander Vladishev [ 2024 Aug 15 ]

You can find additional information here: Script timeout

Comment by Markku Leiniö [ 2024 Aug 16 ]

Confirmed: Whatever is configured in zabbix_proxy.conf for Timeout directive, is sent to the active agent in the timeout field with the command to execute.

That conflicts with what is said in the ZCS training materials and in the documentation (https://www.zabbix.com/documentation/7.0/en/manual/appendix/config/zabbix_proxy#timeout). Do you want me to open a new issue on that?

(Actually that timeout field in the response from proxy to agent is not even documented: https://www.zabbix.com/documentation/7.0/en/manual/appendix/items/activepassive#active-checks)

Comment by Markku Leiniö [ 2024 Aug 16 ]

You can find additional information here: Script timeout

Btw the error in the Script timeout documentation ("Timeout while executing a shell script.") is different from the error described in this issue ("timeout while retrieving result for remote command").

Comment by Phil Z. [ 2025 Mar 19 ]

Also confirmed: tried tuning every parameter related to timeout. Nothing helped, so my Zabbix is useless now, because it isn't able to  fix remote machines.

Anybody made success config? Or resolved shomehow?

Comment by Michael Redbourne [ 2025 Mar 19 ]

Hey Phil,

Post in the Zabbix forums - https://zabbix.com/forum - (and tag me @MRedbourne). This isn't a place for support questions. But yes, I have this working.

Edit: Maker sure to include your Zabbix versions (agent, server, proxy, etc) along with target OS version.

Comment by gofree [ 2025 Apr 17 ]

Funny thing , we did encounter this before - solved by adding one passive item on to the host ( not sure if it has to be working , ours is ). After some time we did encounter it again ( the first time solution was forgotten ) and here we're again - adding passive item to the host solved it again. Try it in your case if using only actove items on the host.

Comment by Alexander Vladishev [ 2025 Apr 17 ]

The maximum script execution timeout, depending on the proxy and agent connection type, can be calculated using the following formulas:

Connection type Max script timeout formula Required proxy Timeout value Required server Timeout value
Active agent via active proxy ProxyConfigFrequency (proxy) + RefreshActiveChecks (agent) + script execution time > RefreshActiveChecks (agent) + script execution time  
Passive agent via active proxy ProxyConfigFrequency (proxy) + script execution time > script execution time  
Active agent via passive proxy ProxyConfigFrequency (server) + RefreshActiveChecks (agent) + script execution time > RefreshActiveChecks (agent) + script execution time  
Passive agent via passive proxy ProxyConfigFrequency (server) + script execution time > script execution time  
Active agent directly via server RefreshActiveChecks (agent) + script execution time   > RefreshActiveChecks (agent) + script execution time
Passive agent directly via server script execution time   > script execution time
Comment by Brian M [ 2025 Apr 30 ]

gofree's comment about fixing this issue by adding a dummy passive item to the host worked for me.  I would suggest that anybody who has this issue to give this a shot.

Comment by Tomek [ 2025 May 12 ]

I have the same problem,
on the server I have set "Timeout = 30", and on the client "RefreshActiveChecks = 5",
scripts that take up to 24 seconds to execute work correctly, scripts from 25 to 30 seconds randomly (they will work or not),
scripts up to 30 seconds do not work.

The only solution I found to make scripts longer than 30 seconds work is editing the file "src/zabbix_server/server.c"
from

{"Timeout", &zbx_config_timeout, ZBX_CFG_TYPE_INT, ZBX_CONF_PARM_OPT, 1, 30}
,​

to

{"Timeout", &zbx_config_timeout, ZBX_CFG_TYPE_INT, ZBX_CONF_PARM_OPT, 1, 300}
,​

then I compile the program and change "Timeout = 300" on the server and I have no problem running scripts that last about 50 seconds

Comment by Vladislavs Sokurenko [ 2025 Aug 04 ]

Does increasing Timeout in Zabbix Server configuration file help with the issue ?

Comment by Andrew A [ 2025 Aug 05 ]

vso The maximum value allowed for Timeout is 30 seconds as per https://www.zabbix.com/documentation/current/en/manual/appendix/config/zabbix_server#timeout so this appears to be the maximum possible time that Zabbix Server will wait to receive the results from a script execution, regardless of other time values that might be in effect.

As the table created by sasha shows, the effective formula is

(server Timeout [30 seconds] - ProxyConfigFrequency - RefreshActiveChecks) = maximum_script_execution_time

As Xin has shown, modifying the source code to allow server Timeout values larger than 30 seconds is necessary to to increase the effective maximum script execution time.

Comment by Vladislavs Sokurenko [ 2025 Aug 06 ]

30 seconds should have been enough mrcomps what version of Zabbix agent is used, so it falls due to additional 5 seconds or so ?

Comment by Vladislavs Sokurenko [ 2025 Aug 08 ]

Fixed in pull request feature/ZBX-26510-7.0-2

Comment by Vladislavs Sokurenko [ 2025 Aug 11 ]

Fixed in:

Generated at Wed Sep 17 22:30:11 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.