Special Handling of redis network events-stale event

Source: Internet
Author: User
In the aeprocessevents function of the AE. c file, the following code is provided for handling the returned network events:

int rfired = 0; /* note the fe->mask & mask & ... code: maybe an already processed  * event removed an element that fired and we still didn't  * processed, so we check if the event is still valid. */   if (fe->mask & mask & AE_READABLE) {          rfired = 1;          fe->rfileProc(eventLoop,fd,fe->clientData,mask);       }    if (fe->mask & mask & AE_WRITABLE) {          if (!rfired || fe->wfileProc != fe->rfileProc)               fe->wfileProc(eventLoop,fd,fe->clientData,mask);      }

First, is it weird? When both readable and writable Callbacks are triggered on a connection, only the readable callback (rfileproc) is executed )!

The reason is that clientdata may be free of clientdata in rfileproc. In this case, wfileproc will be coredump.

(See readhandler of the redis-benchmark.c, which has a clientdone () call back to release clientdata)

Such code is a bit like a class member function in C ++. There is a delete this... Basically belongs to Hu laibehavior

I have to say that writing is really cool, and resource management is very messy.

This is also why C code is a little disgusted. Apart from nginx, C code is ugly and difficult to maintain,

And it is difficult to solve the memory problem.

PS: similar processing is also available in nginx, which is called stale event. I don't think there are many comments. I think it is a design problem that has led to so many concerns.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.