Skip to content

asking for longer prompts triggers - Request processing failed: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:11434/api/chat": timeout #1634

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
vzR opened this issue Oct 30, 2024 · 5 comments
Labels

Comments

@vzR
Copy link

vzR commented Oct 30, 2024

Hello, I see that there was a possible duplicate of this but it was closed as not having provided enough info

Bug description
i have tried to use phi3, llama3.2:1b, llama3.2:latest...
i have asked questions with wordy answers inside the terminal and i get a response every time.
However, with the spring ai project, every time i ask a question that should generate a somewhat longer answer, i get the above error;
if i ask plain things like 'count to 10' - i get a response; If i ask 'count to 100' - error above followed by 'Socket closed '

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:11434/api/chat": timeout] with root cause

java.net.SocketException: Socket closed
	at java.base/sun.nio.ch.NioSocketImpl.endRead(NioSocketImpl.java:253) ~[na:na]
	at java.base/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:332) ~[na:na]
	at java.base/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:355) ~[na:na]
	at java.base/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:808) ~[na:na]
	at java.base/java.net.Socket$SocketInputStream.read(Socket.java:966) ~[na:na]
	at okio.InputStreamSource.read(JvmOkio.kt:93) ~[okio-jvm-3.6.0.jar:na]
	at okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:128) ~[okio-jvm-3.6.0.jar:na]
	at okio.RealBufferedSource.indexOf(RealBufferedSource.kt:430) ~[okio-jvm-3.6.0.jar:na]
	at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.kt:323) ~[okio-jvm-3.6.0.jar:na]

Environment

<properties>
        <java.version>17</java.version>
        <spring-ai.version>1.0.0-M3</spring-ai.version>
   </properties>
<dependency>
                <groupId>org.springframework.ai</groupId>
                <artifactId>spring-ai-bom</artifactId>
                <version>${spring-ai.version}</version>
                <type>pom</type>
                <scope>import</scope>
</dependency>

i run an amazon Linux EC2 with processor:
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
16GB RAM

-- could these limited resources be problematic?
Steps to reproduce
created a plain spring boot project with spring-ai-bom;
added a plain ChatController with contents

private final ChatModel chatModel;
public ChatController(ChatModel chatModel) {
this.chatModel = chatModel;
}

@GetMapping("/ask")
public String askQuestion(@RequestParam(value = "message") String message) {
    return chatModel.call(message);
}

Expected behavior
i expect a response from the model which is as large as its output context (1024 chars for ex for llama3.2:1b)

Minimal Complete Reproducible example
setup as above and ask to provide a long description;

@ThomasVitale
Copy link
Contributor

You might need to increase the default timeout value.

If you're using Spring Boot 3.3, then you can use a RestClientCustomizer.

@Bean
RestClientCustomizer restClientCustomizer() {
      return restClientBuilder -> {
          restClientBuilder
                  .requestFactory(new BufferingClientHttpRequestFactory(
                          ClientHttpRequestFactories.get(ClientHttpRequestFactorySettings.DEFAULTS
                                          .withConnectTimeout(Duration.ofSeconds(60))
                                          .withReadTimeout(Duration.ofSeconds(120))
                          )));
      };
}

In Spring Boot 3.4, you can customise that via configuration properties:

spring:
  http:
    client:
      connect-timeout: 30s
      read-timeout: 120s

There is a feature request to make these timeouts more easily configurable for Spring AI: #512

@vzR
Copy link
Author

vzR commented Oct 31, 2024

thanks a lot for the quick reply - indeed this works - amazing help; to me this issue can be closed.

@ThomasVitale
Copy link
Contributor

@vzR happy to help! I'm glad that fixed the problem. I think you have the option down here to close the issue.

@vzR
Copy link
Author

vzR commented Oct 31, 2024

thanks for the quick help! closing the issue.

@vzR vzR closed this as completed Oct 31, 2024
@MusicBoooox
Copy link

You might need to increase the default timeout value.

If you're using Spring Boot 3.3, then you can use a RestClientCustomizer.

@Bean
RestClientCustomizer restClientCustomizer() {
      return restClientBuilder -> {
          restClientBuilder
                  .requestFactory(new BufferingClientHttpRequestFactory(
                          ClientHttpRequestFactories.get(ClientHttpRequestFactorySettings.DEFAULTS
                                          .withConnectTimeout(Duration.ofSeconds(60))
                                          .withReadTimeout(Duration.ofSeconds(120))
                          )));
      };
}

In Spring Boot 3.4, you can customise that via configuration properties:

spring:
  http:
    client:
      connect-timeout: 30s
      read-timeout: 120s

There is a feature request to make these timeouts more easily configurable for Spring AI: #512

If I use springboot3.2,what I should do?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants