Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Error in http server when open_fn fail. ESP-IDF is ok (GIT8266O-407) #836

Open
hiperiondev opened this issue Mar 1, 2020 · 0 comments
Open

Comments

@hiperiondev
Copy link

When defined open_fn function not return ESP_OK http server enter in a infinite loop.
The problem is in components/esp_http_server/src/httpd_sess.c.
Replacing the same file from ESP-IDF works correct.

differences:

--- components/esp_http_server/src/httpd_sess.c 2020-02-29 22:00:11.650552816 -0300
+++ components/esp_http_server/src/httpd_sess.c.orig 2020-02-20 00:14:35.808278894 -0300
@@ -19,6 +19,7 @@

#include <esp_http_server.h>
#include "esp_httpd_priv.h"
+#include <sys/fcntl.h>

static const char *TAG = "httpd_sess";

@@ -77,11 +78,7 @@
/* Call user-defined session opening function */
if (hd->config.open_fn) {
esp_err_t ret = hd->config.open_fn(hd, hd->hd_sd[i].fd);

  •            if (ret != ESP_OK) {
    
  •                httpd_sess_delete(hd, hd->hd_sd[i].fd);
    
  •                ESP_LOGD(TAG, LOG_FMT("open_fn failed for fd = %d"), newfd);
    
  •                return ret;
    
  •            }
    
  •            if (ret != ESP_OK) return ret;
           }
           return ESP_OK;
       }
    

@@ -196,10 +193,10 @@
/** Check if a FD is valid */
static int fd_is_valid(int fd)
{

  • return fcntl(fd, F_GETFD) != -1 || errno != EBADF;
  • return fcntl(fd, F_GETFD, 0) != -1 || errno != EBADF;
    }

-static inline uint64_t httpd_sess_get_lru_counter(void)
+static inline uint64_t httpd_sess_get_lru_counter()
{
static uint64_t lru_counter = 0;
return lru_counter++;
@@ -378,10 +375,6 @@
{
struct sock_db *sock_db = (struct sock_db *)arg;
if (sock_db) {

  •    if (sock_db->lru_counter == 0) {
    
  •        ESP_LOGD(TAG, "Skipping session close for %d as it seems to be a race condition", sock_db->fd);
    
  •        return;
    
  •    }
       int fd = sock_db->fd;
       struct httpd_data *hd = (struct httpd_data *) sock_db->handle;
       httpd_sess_delete(hd, fd);
    
@github-actions github-actions bot changed the title Error in http server when open_fn fail. ESP-IDF is ok Error in http server when open_fn fail. ESP-IDF is ok (GIT8266O-407) Mar 1, 2020
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

No branches or pull requests

1 participant