You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/08/11 08:59:56 UTC

[GitHub] [apisix] spacewander opened a new pull request, #7648: fix: use a new way to manage clean_handler

spacewander opened a new pull request, #7648:
URL: https://github.com/apache/apisix/pull/7648

   Signed-off-by: spacewander <sp...@gmail.com>
   
   ### Description
   
   <!-- Please include a summary of the change and which issue is fixed. -->
   <!-- Please also include relevant motivation and context. -->
   
   Fixes #7633
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [ ] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [ ] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
   
   <!--
   
   Note
   
   1. Mark the PR as draft until it's ready to be reviewed.
   2. Always add/update tests for any changes unless you have a good reason.
   3. Always update the documentation to reflect the changes made in the PR.
   4. Make a new commit to resolve conversations instead of `push -f`.
   5. To resolve merge conflicts, merge master instead of rebasing.
   6. Use "request review" to notify the reviewer after making changes.
   7. Only a reviewer can mark a conversation as resolved.
   
   -->
   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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


[GitHub] [apisix] starsz commented on a diff in pull request #7648: fix: use a new way to manage clean_handler

Posted by GitBox <gi...@apache.org>.
starsz commented on code in PR #7648:
URL: https://github.com/apache/apisix/pull/7648#discussion_r945373622


##########
apisix/core/config_util.lua:
##########
@@ -56,23 +58,56 @@ end
 -- or cancelled. Note that Nginx worker exit doesn't trigger the clean handler.
 -- Return an index so that we can cancel it later.
 function _M.add_clean_handler(item, func)
-    local idx = #item.clean_handlers + 1
-    item.clean_handlers[idx] = func
-    return idx
+    if not item.clean_handlers._id then
+        item.clean_handlers._id = 1
+    end
+
+    local id = item.clean_handlers._id
+    item.clean_handlers._id = item.clean_handlers._id + 1

Review Comment:
   > > If `item.clean_handlers._id` is nil. The result will be two because we set `item.clean_handlers._id = 1` at line 62.
   > 
   > Yes. But we store the id (which is assigned before `item.clean_handlers._id = item.clean_handlers._id + 1`), so the first id is still 1.
   
   Got it.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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


[GitHub] [apisix] starsz commented on a diff in pull request #7648: fix: use a new way to manage clean_handler

Posted by GitBox <gi...@apache.org>.
starsz commented on code in PR #7648:
URL: https://github.com/apache/apisix/pull/7648#discussion_r944058151


##########
apisix/core/config_util.lua:
##########
@@ -56,23 +58,56 @@ end
 -- or cancelled. Note that Nginx worker exit doesn't trigger the clean handler.
 -- Return an index so that we can cancel it later.
 function _M.add_clean_handler(item, func)
-    local idx = #item.clean_handlers + 1
-    item.clean_handlers[idx] = func
-    return idx
+    if not item.clean_handlers._id then
+        item.clean_handlers._id = 1
+    end
+
+    local id = item.clean_handlers._id
+    item.clean_handlers._id = item.clean_handlers._id + 1

Review Comment:
   If `item.clean_handlers._id` is nil. The result will be two because we set `item.clean_handlers._id = 1` at line 62.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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


[GitHub] [apisix] zhangliweixyz commented on pull request #7648: fix: use a new way to manage clean_handler

Posted by GitBox <gi...@apache.org>.
zhangliweixyz commented on PR #7648:
URL: https://github.com/apache/apisix/pull/7648#issuecomment-1354083285

   ![image](https://user-images.githubusercontent.com/70928799/208005770-8e0f864d-3bbe-4ea1-bca1-5c87087dc50a.png)
   
   Hi, as for this bug, can I change the code like this? if f not nil and call f, and I'm not sure if there is other problem


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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


[GitHub] [apisix] spacewander commented on a diff in pull request #7648: fix: use a new way to manage clean_handler

Posted by GitBox <gi...@apache.org>.
spacewander commented on code in PR #7648:
URL: https://github.com/apache/apisix/pull/7648#discussion_r944132790


##########
apisix/core/config_util.lua:
##########
@@ -56,23 +58,56 @@ end
 -- or cancelled. Note that Nginx worker exit doesn't trigger the clean handler.
 -- Return an index so that we can cancel it later.
 function _M.add_clean_handler(item, func)
-    local idx = #item.clean_handlers + 1
-    item.clean_handlers[idx] = func
-    return idx
+    if not item.clean_handlers._id then
+        item.clean_handlers._id = 1
+    end
+
+    local id = item.clean_handlers._id
+    item.clean_handlers._id = item.clean_handlers._id + 1

Review Comment:
   > If `item.clean_handlers._id` is nil. The result will be two because we set `item.clean_handlers._id = 1` at line 62.
   
   Yes. But we store the id (which is assigned before `item.clean_handlers._id = item.clean_handlers._id + 1`), so the first id is still 1.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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


[GitHub] [apisix] spacewander merged pull request #7648: fix: use a new way to manage clean_handler

Posted by GitBox <gi...@apache.org>.
spacewander merged PR #7648:
URL: https://github.com/apache/apisix/pull/7648


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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


[GitHub] [apisix] spacewander commented on a diff in pull request #7648: fix: use a new way to manage clean_handler

Posted by GitBox <gi...@apache.org>.
spacewander commented on code in PR #7648:
URL: https://github.com/apache/apisix/pull/7648#discussion_r944131931


##########
apisix/core/config_util.lua:
##########
@@ -56,23 +58,56 @@ end
 -- or cancelled. Note that Nginx worker exit doesn't trigger the clean handler.
 -- Return an index so that we can cancel it later.
 function _M.add_clean_handler(item, func)
-    local idx = #item.clean_handlers + 1
-    item.clean_handlers[idx] = func
-    return idx
+    if not item.clean_handlers._id then
+        item.clean_handlers._id = 1
+    end
+
+    local id = item.clean_handlers._id
+    item.clean_handlers._id = item.clean_handlers._id + 1

Review Comment:
   > What is the `clean_handlers._id` used for?
   
   It is used to provide id for the handlers.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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


[GitHub] [apisix] tzssangglass commented on a diff in pull request #7648: fix: use a new way to manage clean_handler

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #7648:
URL: https://github.com/apache/apisix/pull/7648#discussion_r944106494


##########
apisix/core/config_util.lua:
##########
@@ -56,23 +58,56 @@ end
 -- or cancelled. Note that Nginx worker exit doesn't trigger the clean handler.
 -- Return an index so that we can cancel it later.
 function _M.add_clean_handler(item, func)
-    local idx = #item.clean_handlers + 1
-    item.clean_handlers[idx] = func
-    return idx
+    if not item.clean_handlers._id then
+        item.clean_handlers._id = 1
+    end
+
+    local id = item.clean_handlers._id
+    item.clean_handlers._id = item.clean_handlers._id + 1

Review Comment:
   What is the `clean_handlers._id` used for?



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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


[GitHub] [apisix] zhangliweixyz commented on pull request #7648: fix: use a new way to manage clean_handler

Posted by GitBox <gi...@apache.org>.
zhangliweixyz commented on PR #7648:
URL: https://github.com/apache/apisix/pull/7648#issuecomment-1341839508

   ![image](https://user-images.githubusercontent.com/70928799/206332373-ef022354-df77-4702-84e9-f5b19da3a9e2.png)
   
   My apisix version is 2.15.0,can I replace this 4 files in my apisix directly and restart apisix


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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