Skip to content

Add flag to suppress stream errors #6458

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/mysqlnd/mysqlnd_vio.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ MYSQLND_METHOD(mysqlnd_vio, post_connect_set_opt)(MYSQLND_VIO * const vio, const
}

net_stream->chunk_size = vio->data->options.net_read_buffer_size;
net_stream->flags |= PHP_STREAM_FLAG_SUPPRESS_ERRORS;
}

DBG_VOID_RETURN;
Expand Down
9 changes: 0 additions & 9 deletions ext/mysqlnd/mysqlnd_wireprotocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,6 @@ size_t php_mysqlnd_cmd_write(MYSQLND_CONN_DATA * conn, void * _packet)
MYSQLND_VIO * vio = conn->vio;
MYSQLND_STATS * stats = conn->stats;
MYSQLND_CONNECTION_STATE * connection_state = &conn->state;
const unsigned int error_reporting = EG(error_reporting);
size_t sent = 0;

DBG_ENTER("php_mysqlnd_cmd_write");
Expand All @@ -981,10 +980,6 @@ size_t php_mysqlnd_cmd_write(MYSQLND_CONN_DATA * conn, void * _packet)
*/
pfc->data->m.reset(pfc, stats, error_info);

if (error_reporting) {
EG(error_reporting) = 0;
}

MYSQLND_INC_CONN_STATISTIC(stats, STAT_PACKETS_SENT_CMD);

#ifdef MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND
Expand Down Expand Up @@ -1017,10 +1012,6 @@ size_t php_mysqlnd_cmd_write(MYSQLND_CONN_DATA * conn, void * _packet)
}
}
end:
if (error_reporting) {
/* restore error reporting */
EG(error_reporting) = error_reporting;
}
if (!sent) {
SET_CONNECTION_STATE(connection_state, CONN_QUIT_SENT);
}
Expand Down
4 changes: 4 additions & 0 deletions main/php_streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ struct _php_stream_wrapper {

#define PHP_STREAM_FLAG_NO_FCLOSE 0x80

/* Suppress generation of PHP warnings on stream read/write errors.
* Currently for internal use only. */
#define PHP_STREAM_FLAG_SUPPRESS_ERRORS 0x100

#define PHP_STREAM_FLAG_WAS_WRITTEN 0x80000000

struct _php_stream {
Expand Down
8 changes: 6 additions & 2 deletions main/streams/plain_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
/* TODO: Should this be treated as a proper error or not? */
return bytes_written;
}
php_error_docref(NULL, E_NOTICE, "Write of %zu bytes failed with errno=%d %s", count, errno, strerror(errno));
if (!(stream->flags & PHP_STREAM_FLAG_SUPPRESS_ERRORS)) {
php_error_docref(NULL, E_NOTICE, "Write of %zu bytes failed with errno=%d %s", count, errno, strerror(errno));
}
}
return bytes_written;
} else {
Expand Down Expand Up @@ -426,7 +428,9 @@ static ssize_t php_stdiop_read(php_stream *stream, char *buf, size_t count)
} else if (errno == EINTR) {
/* TODO: Should this be treated as a proper error or not? */
} else {
php_error_docref(NULL, E_NOTICE, "Read of %zu bytes failed with errno=%d %s", count, errno, strerror(errno));
if (!(stream->flags & PHP_STREAM_FLAG_SUPPRESS_ERRORS)) {
php_error_docref(NULL, E_NOTICE, "Read of %zu bytes failed with errno=%d %s", count, errno, strerror(errno));
}

/* TODO: Remove this special-case? */
if (errno != EBADF) {
Expand Down
9 changes: 6 additions & 3 deletions main/streams/xp_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,13 @@ static ssize_t php_sockop_write(php_stream *stream, const char *buf, size_t coun
}
}

estr = php_socket_strerror(err, NULL, 0);
php_error_docref(NULL, E_NOTICE, "Send of " ZEND_LONG_FMT " bytes failed with errno=%d %s",
if (!(stream->flags & PHP_STREAM_FLAG_SUPPRESS_ERRORS)) {
estr = php_socket_strerror(err, NULL, 0);
php_error_docref(NULL, E_NOTICE,
"Send of " ZEND_LONG_FMT " bytes failed with errno=%d %s",
(zend_long)count, err, estr);
efree(estr);
efree(estr);
}
}

if (didwrite > 0) {
Expand Down