Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 63d0198

Browse filesBrowse files
authored
Fixed bug of get segment ptr in sky_plugin_error_init() (#478)
1 parent e49530b commit 63d0198
Copy full SHA for 63d0198

File tree

Expand file treeCollapse file tree

3 files changed

+22
-6
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+22
-6
lines changed

‎src/sky_plugin_error.cc

Copy file name to clipboardExpand all lines: src/sky_plugin_error.cc
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "sky_plugin_error.h"
2020
#include "php_skywalking.h"
2121
#include "segment.h"
22+
#include "sky_utils.h"
2223
#include <string>
2324

2425
#if PHP_VERSION_ID < 80000
@@ -86,12 +87,13 @@ void sky_plugin_error_cb(int type, zend_string *error_filename, const uint32_t e
8687
#endif
8788

8889
if (!SKYWALKING_G(is_swoole) && SKYWALKING_G(enable) && SKYWALKING_G(segment) != nullptr) {
89-
auto *segments = static_cast<std::map<uint64_t, Segment *> *>SKYWALKING_G(segment);
90-
auto segment = segments->at(0);
91-
auto span = segment->firstSpan();
92-
span->addLog(level, log);
93-
if (isError) {
94-
span->setIsError(true);
90+
auto segment = sky_get_segment(0);
91+
if (segment != nullptr) {
92+
auto span = segment->firstSpan();
93+
span->addLog(level, log);
94+
if (isError) {
95+
span->setIsError(true);
96+
}
9597
}
9698
}
9799

‎src/sky_utils.cc

Copy file name to clipboardExpand all lines: src/sky_utils.cc
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ int64_t sky_find_swoole_fd(zend_execute_data *execute_data) {
124124
return -1;
125125
}
126126

127+
Segment *sky_get_segment(int64_t request_id) {
128+
if (SKYWALKING_G(segment) == nullptr) {
129+
return nullptr;
130+
}
131+
auto *segments = static_cast<std::unordered_map<uint64_t, Segment *> *>SKYWALKING_G(segment);
132+
auto it = segments->find(request_id);
133+
if (it != segments->end()) {
134+
return it->second;
135+
}
136+
return nullptr;
137+
}
138+
127139
Segment *sky_get_segment(zend_execute_data *execute_data, int64_t request_id) {
128140

129141
if (SKYWALKING_G(segment) == nullptr) {

‎src/sky_utils.h

Copy file name to clipboardExpand all lines: src/sky_utils.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ zval *sky_read_property(zval *obj, const char *property, int parent);
3636

3737
int64_t sky_find_swoole_fd(zend_execute_data *execute_data);
3838

39+
Segment *sky_get_segment(int64_t request_id);
40+
3941
Segment *sky_get_segment(zend_execute_data *execute_data, int64_t request_id);
4042

4143
bool sky_insert_segment(uint64_t request_id, Segment *segment);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.