Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 增加React-neo4j应用程序中的超时时间_Javascript_Reactjs_Neo4j_Axios - Fatal编程技术网

Javascript 增加React-neo4j应用程序中的超时时间

Javascript 增加React-neo4j应用程序中的超时时间,javascript,reactjs,neo4j,axios,Javascript,Reactjs,Neo4j,Axios,我正在尝试增加我的React应用程序的超时时间。我使用的是axios,因此最初我尝试: axios.post('/gene_info', postData, {timeout: timeoutVal}); 它不起作用,有相应的线程处理它: 因此,我尝试了以下代码: let CancelToken = axios.CancelToken; const source = CancelToken.source(); try { let response

我正在尝试增加我的
React
应用程序的超时时间。我使用的是
axios
,因此最初我尝试:

axios.post('/gene_info', postData, {timeout: timeoutVal});
它不起作用,有相应的线程处理它:

因此,我尝试了以下代码:

 let CancelToken = axios.CancelToken;
      const source = CancelToken.source();
      try {
          let response = null;
          setTimeout(() => {
              if (response === null) {
                  source.cancel();
              }
          }, 60 * 1500 * 1000);

          response = await axios.post('/gene_info', postData, {cancelToken: source.token});
          console.log(response);
      } catch (error) {
          console.log(error);
      }
而且它也不起作用。请求超时,我看到空响应错误,即使在
Node.js
后端,我看到结果返回正确。在后端,我向
Neo4j
数据库发出了一个长时间运行的请求。我怀疑它可能超时了,所以我在
neo4j.config
文件中添加了以下行:

unsupported.dbms.executiontime_limit.enabled=true
unsupported.dbms.executiontime_limit.time=99999999999999s
我在这里发现:

并重新启动了neo4j,但也没有任何帮助。以下是我在航站楼看到的情况:

我不确定这个
POST/gene_info--ms---
是什么意思,问题是仍然在前端还是后端,但我怀疑
neo4j
现在超时了,但它仍然在计算我使用
console.log()
语句看到的结果。如有任何建议,将不胜感激

更新

我尝试使用
Reacts
fetch
,但仍然不起作用。代码如下:

fetchWithTimeout = (url, postData, timeout) => {
let didTimeOut = false;

new Promise(function(resolve, reject) {
    const timeout = setTimeout(function() {
        didTimeOut = true;
        reject(new Error('Request timed out'));
    }, timeout);

    fetch(url, {
        method: 'POST',
        headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        },
        timeout: timeout,
        body: JSON.stringify(postData)
    })
    .then(function(response) {
        // Clear the timeout as cleanup
        clearTimeout(timeout);
        if(!didTimeOut) {
            console.log('fetch good! ', response);
            resolve(response);
        }
    })
    .catch(function(err) {
        console.log('fetch failed! ', err);

        // Rejection already happened with setTimeout
        if(didTimeOut) return;
        // Reject with error
        reject(err);
    });
})
.then(function() {
    // Request success and no timeout
    console.log('good promise, no timeout! ');
})
.catch(function(err) {
    // Error: response error, request timeout or runtime error
    console.log('promise error! ', err);
});
}
然后我像这样调用这个函数:

let postData = {"jsonData": geneNameArr,
                    "datasetName": this.props.datasetName};
this.fetchWithTimeout('/gene_info', postData, timeout).then((response) => {
        console.log("fetchWithTimeout is done!");
        console.log(response);
      });
更新

我尝试使用
axios.create()
函数,但没有成功:

  const axiosInstance = axios.create({
        baseURL: '/gene_info',
        timeout: timeout
    });

    axiosInstance.post('', postData).then((response) => {
      console.log("axios request is done with create() method");
      console.log(response);
    });
如果前端似乎没有工作,我会认为是来自
neo4j
驱动程序的超时,即使结果以某种方式返回。以下是我为驱动程序使用的代码:

router.post('/gene_info', function(req, res) {
...
...
var driver = dbUtils.driver;
const session = driver.session();
session.run(
  full_query,
  {}
 ).then(result => {
  const exprData = chartService.prepareGeneInfoData(result, '');
  res.json({
    exprData
  });

  session.close();
});
})

或者它也可以是
express.Router()用于处理
get
post
请求,在后端使用
Node.js

如果要在axios中配置超时,可以使用

const axiosInstance = axios.create({
    baseURL: "http://example.com/api/",
    timeout: 5000
});

用所需的超时值替换
5000

最终我找到了在这里工作的解决方案:

我以以下方式使用了
setConnectionTimeout()
函数:

router.post('/gene_info', setConnectionTimeout('12h'), function(req, res) {
    ...
})

不,这也没用,而且超时一直在发生。我用我使用的
axios.create()
更新了问题的代码。您是否将超时设置为
timeout:timeout
?还是第二次超时的值?你可以通过邮递员确认这是否是客户端问题。使用邮递员发送请求,如果同样失败,则可能是服务器端未
Send
ing响应的问题。