Skip to content

Conversation

emogua
Copy link

@emogua emogua commented Sep 3, 2025

Fix(http-task): readTimeOut configuration from task input does not work, readTimeOut always max to default 3 minutes

Pull Request type

  • [√] Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • WHOSUSING.md
  • Other (please describe):

NOTE: Please remember to run ./gradlew spotlessApply to fix any format violations.

Changes in this PR

I wrote a test case to replay this issue:
`/*

  • Copyright 2021 Conductor Authors.
  • Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  • the License. You may obtain a copy of the License at
  • http://www.apache.org/licenses/LICENSE-2.0
  • Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  • an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  • specific language governing permissions and limitations under the License.
    */
    package com.netflix.conductor.tasks.http;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.*;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.netflix.conductor.tasks.http.providers.RestTemplateProvider;
import org.springframework.web.client.RestTemplate;

import java.time.LocalDateTime;
import java.util.Collections;

// test
@RestController
@RequestMapping("test")
public class TestHttpRequest {
protected RestTemplateProvider restTemplateProvider;
protected ObjectMapper objectMapper;

public TestHttpRequest(RestTemplateProvider restTemplateProvider, ObjectMapper objectMapper) {
    this.restTemplateProvider = restTemplateProvider;
    this.objectMapper = objectMapper;
}

@GetMapping("test")
public String test() {
    StopWatch stopWatch = new StopWatch("http task run time statistic");
    stopWatch.start("task started at " + LocalDateTime.now());
    System.out.println("task started at " + LocalDateTime.now());
    try {
        HttpTask.Input input = this.objectMapper.readValue("{ \"headers\": {}, \"method\": \"POST\", \"readTimeOut\": 300000, \"body\": { \"nextExecute1\": null, \"preV2\": null, \"preV1\": null, \"retryNum\": \"10\", \"test\": \"false\", \"extendParam\": null, \"param\": \"aabb\", \"orderRequestTaskId\": \"ba7870be-67e6-4fee-8bf1-25987c3433d9\", \"platform\": \"SELF\", \"retrySleepTime\": \"3600000\", \"nextExecute2\": null }, \"uri\": \"http://xxx.com/iac/v1/execute/cxxx\", \"connectionTimeOut\": 3600000 }", HttpTask.Input.class);
        RestTemplate restTemplate = this.restTemplateProvider.getRestTemplate(input);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.valueOf(input.getContentType()));
        headers.setAccept(Collections.singletonList(MediaType.valueOf(input.getAccept())));

        input.getHeaders().forEach(
                (key, value) -> {
                    if (value != null) {
                        headers.add(key, value.toString());
                    }
                });

        HttpEntity<Object> request = new HttpEntity<>(input.getBody(), headers);
        ResponseEntity<String> responseEntity =
                restTemplate.exchange(
                        input.getUri(),
                        HttpMethod.valueOf(input.getMethod()),
                        request,
                        String.class);
    } catch (Exception e) {
        System.out.println(e);
    }

    stopWatch.stop();
    System.out.println(stopWatch.prettyPrint());
    return "test";
}

}
`
When I call a http request to http://xxx.com/iac/v1/execute/cxxx(not real path), it will block for a long time without response.
And I config readTimeOut as 300000ms (5 minutes), but after 3 minutes later, an exception throw out:
Failed to invoke HTTP task due to: java.lang.Exception: I/O error on POST request for "http://xxx.com/iac/v1/execute/cxxx": Read timed out

I think is should try to use the readTimeOut config as the old version(like 2.31.0), I know there is a timeout config for server side could also less than the readTimeOut config.

After my modification, I have tested the test case, and it worked.

Appendix, there is a setReadTimeOut function in HttpComponentsClientHttpRequestFactory in spring-framework versions >= 6.2
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.html

Describe the new behavior from this PR, and why it's needed
Issue #

Alternatives considered

Describe alternative implementation you have considered

…rk, readTimeOut always max to default 3 minutes
@v1r3n v1r3n merged commit cf7feca into conductor-oss:main Sep 14, 2025
2 checks passed
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.

2 participants