You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/11/23 17:55:18 UTC

[GitHub] [incubator-tvm] rkimball opened a new pull request #6953: Add retry to sockets on EINTR error

rkimball opened a new pull request #6953:
URL: https://github.com/apache/incubator-tvm/pull/6953


   Long-running system calls like socket recv or send may be interrupted and should be retried. If a call is interrupted errno is set to EINTR. Added retry_call which retries a call in hopes of reducing the occurrence of this error.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen commented on pull request #6953: Add retry to sockets on EINTR error

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #6953:
URL: https://github.com/apache/incubator-tvm/pull/6953#issuecomment-732435998


   cc @areusch 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] areusch commented on pull request #6953: Add retry to sockets on EINTR error

Posted by GitBox <gi...@apache.org>.
areusch commented on pull request #6953:
URL: https://github.com/apache/incubator-tvm/pull/6953#issuecomment-732439367


   hey @rkimball one case where this may occur is a Ctrl+C-triggered SIGINT. are you encountering that case? if so, this is the mechanism by which we decide to terminate TVM on unix. i previously tried to see if there is a way to work around this by calling back into Python on EINTR to check whether we should actually terminate or just retry, but that is fraught because libtvm.so doesn't depend on Python and we don't want it to. could you elaborate on when you're seeing this undisturbed?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen commented on a change in pull request #6953: Add retry to sockets on EINTR error

Posted by GitBox <gi...@apache.org>.
tqchen commented on a change in pull request #6953:
URL: https://github.com/apache/incubator-tvm/pull/6953#discussion_r528996912



##########
File path: src/support/socket.h
##########
@@ -68,6 +68,28 @@ static inline int poll(struct pollfd* pfd, int nfds, int timeout) {
 
 namespace tvm {
 namespace support {
+
+/*!
+ * \brief Call a function and retry if an EINTR error is encountered.
+ * \param f The function to retry.
+ * \param error_value The error value returned by the call on retry failure.
+ * \return The return code returned by function f or error_value on retry failure.
+ */
+template <typename T>
+T retry_call(std::function<T()> f, T error_value) {
+  errno = 0;
+  T rc = error_value;
+  for (size_t retry = 0; retry < 8; ++retry) {
+    rc = f();
+    if (errno == EINTR) {
+      rc = error_value;
+    } else {
+      break;

Review comment:
       directly return error_value here

##########
File path: src/support/socket.h
##########
@@ -68,6 +68,28 @@ static inline int poll(struct pollfd* pfd, int nfds, int timeout) {
 
 namespace tvm {
 namespace support {
+
+/*!
+ * \brief Call a function and retry if an EINTR error is encountered.
+ * \param f The function to retry.
+ * \param error_value The error value returned by the call on retry failure.
+ * \return The return code returned by function f or error_value on retry failure.
+ */
+template <typename T>
+T retry_call(std::function<T()> f, T error_value) {
+  errno = 0;
+  T rc = error_value;
+  for (size_t retry = 0; retry < 8; ++retry) {

Review comment:
       8 seems to be a magic number, need a constant

##########
File path: src/support/socket.h
##########
@@ -68,6 +68,28 @@ static inline int poll(struct pollfd* pfd, int nfds, int timeout) {
 
 namespace tvm {
 namespace support {
+
+/*!
+ * \brief Call a function and retry if an EINTR error is encountered.
+ * \param f The function to retry.
+ * \param error_value The error value returned by the call on retry failure.
+ * \return The return code returned by function f or error_value on retry failure.
+ */
+template <typename T>
+T retry_call(std::function<T()> f, T error_value) {

Review comment:
       Prefer not using std::function, because that means construction of std::function in cases where it can be inlined. Instead, use the following signature so f can be inlined.
   
   ```c++
   template <typename F>
   T RetryCallWhenEINTR(F f, T error_value);
   ```

##########
File path: src/support/socket.h
##########
@@ -68,6 +68,28 @@ static inline int poll(struct pollfd* pfd, int nfds, int timeout) {
 
 namespace tvm {
 namespace support {
+
+/*!
+ * \brief Call a function and retry if an EINTR error is encountered.
+ * \param f The function to retry.
+ * \param error_value The error value returned by the call on retry failure.
+ * \return The return code returned by function f or error_value on retry failure.
+ */
+template <typename T>
+T retry_call(std::function<T()> f, T error_value) {

Review comment:
       inline this function, as it is in header file.
   
   Use CamelCase 

##########
File path: src/support/socket.h
##########
@@ -68,6 +68,28 @@ static inline int poll(struct pollfd* pfd, int nfds, int timeout) {
 
 namespace tvm {
 namespace support {
+
+/*!
+ * \brief Call a function and retry if an EINTR error is encountered.
+ * \param f The function to retry.
+ * \param error_value The error value returned by the call on retry failure.
+ * \return The return code returned by function f or error_value on retry failure.
+ */
+template <typename T>
+T retry_call(std::function<T()> f, T error_value) {
+  errno = 0;
+  T rc = error_value;
+  for (size_t retry = 0; retry < 8; ++retry) {

Review comment:
       Consider start with a first call to f and return, then the less freqeuent path of retry. The compiler can pick that up as opposed to enter a loop in most of the time.

##########
File path: src/support/socket.h
##########
@@ -68,6 +68,28 @@ static inline int poll(struct pollfd* pfd, int nfds, int timeout) {
 
 namespace tvm {
 namespace support {
+
+/*!
+ * \brief Call a function and retry if an EINTR error is encountered.
+ * \param f The function to retry.
+ * \param error_value The error value returned by the call on retry failure.
+ * \return The return code returned by function f or error_value on retry failure.
+ */
+template <typename T>
+T retry_call(std::function<T()> f, T error_value) {
+  errno = 0;
+  T rc = error_value;

Review comment:
       error_value is not needed if you get the rc in the first call

##########
File path: src/support/socket.h
##########
@@ -68,6 +68,28 @@ static inline int poll(struct pollfd* pfd, int nfds, int timeout) {
 
 namespace tvm {
 namespace support {
+
+/*!
+ * \brief Call a function and retry if an EINTR error is encountered.
+ * \param f The function to retry.
+ * \param error_value The error value returned by the call on retry failure.
+ * \return The return code returned by function f or error_value on retry failure.
+ */
+template <typename T>
+T retry_call(std::function<T()> f, T error_value) {
+  errno = 0;

Review comment:
       not sure if it is the best pratice to set errno, instead, check rc first, then check errno




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen commented on pull request #6953: Add retry to sockets on EINTR error

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #6953:
URL: https://github.com/apache/incubator-tvm/pull/6953#issuecomment-732434059


   It might be helpful to discuss a scenario when this happens. Since in many cases we would indeed want to abort, as opposed to retry when an interrupt happens


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] areusch edited a comment on pull request #6953: Add retry to sockets on EINTR error

Posted by GitBox <gi...@apache.org>.
areusch edited a comment on pull request #6953:
URL: https://github.com/apache/incubator-tvm/pull/6953#issuecomment-732439367


   hey @rkimball one case where this may occur is a Ctrl+C-triggered SIGINT. are you encountering that case? if so, this is the mechanism by which we decide to terminate TVM on posix. i previously tried to see if there is a way to work around this by calling back into Python on EINTR to check whether we should actually terminate or just retry, but that is fraught because libtvm.so doesn't depend on Python and we don't want it to. could you elaborate on when you're seeing this undisturbed?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org