标签: timeout

禁用 golang TCP 中的截止日期

我想对客户端连接设置一个截止日期,他必须在前 10 秒内做某事,否则就会断开连接,如果他确实做了某事,我想删除截止日期。

// meConn = *TCPConn
c.meConn.SetDeadline(time.Now().Add(10 * time.Second))
Run Code Online (Sandbox Code Playgroud)

但文档中没有提及任何有关禁用截止日期的内容。

另外,当满足特定条件时不断更改截止日期是否安全?

time timeout go

1
推荐指数
1
解决办法
5126
查看次数

Objective-C 以非阻塞方式实现超时

我正在调用一个外部异步函数,该函数应在完成后调用回调。
但是,由于该函数是外部的,因此我无法控制其实现,并且我想将超时设置为 5 秒作为示例,并考虑如果在这 5 秒内未调用传递给该外部异步函数的回调,则考虑超时操作。秒。

我目前发现的唯一方法是让当前线程休眠,这实际上会阻塞线程。
这是一个例子:
+(void)myFuncWithCompletion:(void (^ _Nonnull)(BOOL))completion{ BOOL timedOut = NO; BOOL __block finishedAsyncCall = NO; [someObj someAsyncMethod { // completion callback finishedAsyncCall = YES; if (!timedOut) { completion(YES); } }]; // This is the logic I want to fix. My goal is to make something similar but non-blocking. long timeoutInSeconds = 5; long startTime = [[NSDate date] timeIntervalSince1970]; long currTime = [[NSDate date] timeIntervalSince1970]; while (!finishedAsyncCall && startTime + timeoutInSeconds > currTime) { [NSThread sleepForTimeInterval:0]; …

multithreading cocoa-touch asynchronous timeout objective-c

1
推荐指数
1
解决办法
3200
查看次数

curl::curl_fetch_memory(url, handle = handle) 中的错误:已达到超时:发送失败:连接已重置

我正在尝试从 Youtube API 的 5000 个视频中提取评论。当我下载 5 个或更多视频时,我的代码可以完美运行,但是当我插入所需的整个视频列表时,它会在运行几个小时后抛出以下错误。我不确定这意味着什么,或者是否是内存问题。谢谢你!

R 中的代码行:

 comments_1 <- CollectDataYoutube(video1,key,writeToFile = FALSE)
Run Code Online (Sandbox Code Playgroud)

video1:是我拥有的 5000 个视频代码的列表,以便 API 直接从中提取评论。

key:我的 API 密钥是否存储在对象中

错误信息:

curl::curl_fetch_memory(url, handle = handle) 中的错误:已达到超时:发送失败:连接已重置

youtube api timeout r

1
推荐指数
1
解决办法
8059
查看次数

Azure Web 服务 [Web App for Containers (linux)] - 如何定期防止超时

Web Services 定期出现错误日志:

错误 - 站点 YYY 的容器 XXX 未在预期时间限制内启动。经过的时间 = 230.3790706 秒

我设置了微软博客中已经提到的以下设置,但仍然失败:

1. Use the EXPOSE instruction in your Dockerfile to expose port 3000.
2. Use the WEBSITES_PORT app setting with a value of "3000" to expose that port.
Run Code Online (Sandbox Code Playgroud)

如何配置来防止此错误?

web-services timeout azure azure-web-app-service azure-web-app-for-containers

1
推荐指数
1
解决办法
3200
查看次数

如何在没有不稳定功能或外部包的情况下从 mpsc::channel 读取指定的时间?

Receiver我正在尝试在指定的时间内连续读取 a 。我想出了以下解决方案

pub fn get<T>(
    rx: &Receiver<T>,
    get_duration: time::Duration,
) -> Result<(), Err> {
    let (dur_tx, dur_rx) = channel();
    let _ = thread::spawn(move || {
        // timer to kill receiving
        thread::sleep(get_duration);
        let _ = dur_tx.send("tick");
    });

    let mut time_to_break = false;
    while time_to_break == false {
        match rx.try_recv() {
            Ok(resp) => {
                //...
            }
            Err(_) => ()
        }
        thread::sleep(time::Duration::from_millis(1)); // avoid using cpu 100%
        let _ = dur_rx.try_recv().map(|_| time_to_break = true);
    }
    Ok(())
}
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来解决这个问题,而无需不稳定或不推荐使用的功能(例如select)或外部板条箱?

timeout channel rust

1
推荐指数
1
解决办法
1210
查看次数

如何在 http get nodeJS 上设置自定义超时

我找不到有关如何在 NodeJS(使用 Express)中为给定请求设置自定义超时的文档?

以下不起作用......:

https.get("https://externalurl.com", { timeout: 1000 }, (res) => {
    resp.on("timeout", () => {
        console.log("Never fired");
    });
});
Run Code Online (Sandbox Code Playgroud)

这样做也不起作用:

https.get("https://externalurl.com", (req, res) => {
    req.setTimeout(1000);
});
Run Code Online (Sandbox Code Playgroud)

这样做也不行...

https.get("https://externalurl.com", (res) => {

})
.setTimeout(1000);
Run Code Online (Sandbox Code Playgroud)

它总是等待超过 1 秒才抛出错误

有人可以帮忙吗?是否有“官方”方法来为给定请求设置自定义超时?

我的完整 server.ts

// Express server
const app = express();

const PORT = process.env.PORT || 80;
const DIST_FOLDER = join(process.cwd(), "dist/browser");

// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const {
  AppServerModuleNgFactory,
  LAZY_MODULE_MAP,
  ngExpressEngine, …
Run Code Online (Sandbox Code Playgroud)

timeout get request node.js express

1
推荐指数
1
解决办法
4085
查看次数

Newspaper3k API 文章 download() 失败,HTTPSConnectionPool 端口=443 读取超时。(读取超时=7)在 URL 上

在 Firefox 中浏览时,我可以看到http://www.chicagotribune.com/ct-florida-school-shooter-nikolas-cruz-20180217-story.html 。但是,newspaper3k给了我这个错误:

Article download() failed with HTTPSConnectionPool(host='www.chicagotribune.com', port=443): Read timed out. (read timeout=7) on URL http://www.chicagotribune.com/ct-florida-school-shooter-nikolas-cruz-20180217-story.html
Run Code Online (Sandbox Code Playgroud)

我的代码是:

from newspaper import Article
from newspaper import Config

user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0'
config = Config()

config.browser_user_agent = user_agent

url = "https://www.chicagotribune.com/nation-world/ct-florida-school-shooter-nikolas-cruz-20180217-story.html"

page = Article(url, config=config)


page.download()
page.parse()
print(page.text)
Run Code Online (Sandbox Code Playgroud)

我认为像“renewIPAddress()”之类的东西可能会有所帮助,但我不确定如何准确地将其适合此代码。/sf/answers/3534773791/

python https timeout python-3.x newspaper3k

1
推荐指数
1
解决办法
3450
查看次数

指定公共交通中的发布超时

使用 MassTransit 库发布消息时是否可以指定超时值。当消息代理出现故障时如何处理场景。现在看来 Publish 调用无限期地等待。如果能控制这些行为就好了。我们应该依赖取消令牌吗?超时实现可能会更好。

c# publish timeout masstransit rabbitmq

1
推荐指数
1
解决办法
1842
查看次数

了解 MongoDB 超时设置

我很难理解为我的应用程序配置的最佳超时设置是什么 超时设置分为三种类型:

connectTimeoutMS socketTimeoutMS maxTimeMS

除此之外,我们还有:

KeepAlive poolSize 自动重新连接

connectTimeout对应的是应用程序在指定时间范围内无法连接到mongoDB时的超时设置。我认为这会导致异常。

socketTimeoutMS 对应于套接字在关闭之前等待从数据库服务器获取响应。

maxTimeMS 对应于数据库中运行的操作的超时。这会导致异常。

socketTimeout 和 maxTimeout 有什么区别?我的要求是,当对数据库的请求在 {5} 秒后超时时,我必须记录错误代码。未从该数据库收到任何响应。为此目的的最佳超时设置是什么?

poolsize、keepAlive、autoconnected 是如何与超时设置关联的?例子会很有用。

timeout mongodb spring-boot

1
推荐指数
1
解决办法
2万
查看次数

如何在承诺中添加超时?

我读过许多在承诺中添加超时的不同方法,但大多数(如果不是全部)似乎都利用了该setTimeout()方法。根据定义:

The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.
Run Code Online (Sandbox Code Playgroud)

我正在寻找的是一种表达方式:

"If the function executed inside the promise (that will either resolve or
reject the promise), does not complete within a specified x number of
milliseconds, automatically reject or raise an exception."
Run Code Online (Sandbox Code Playgroud)

如果这与上面定义的相同(使用该setTimeout()方法),我们将不胜感激!

javascript timeout node.js promise

1
推荐指数
1
解决办法
5739
查看次数