mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-12-12 16:18:50 +00:00
Add workaround for bulkBarrierPreWrite: unaligned arguments
panic
This commit is contained in:
parent
746f63a9ac
commit
69f8d7fa72
|
@ -139,17 +139,17 @@ func (s *platformInterfaceStub) SendNotification(notification *platform.Notifica
|
|||
return nil
|
||||
}
|
||||
|
||||
func FormatConfig(configContent string) (string, error) {
|
||||
func FormatConfig(configContent string) (*StringBox, error) {
|
||||
options, err := parseConfig(configContent)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
var buffer bytes.Buffer
|
||||
encoder := json.NewEncoder(&buffer)
|
||||
encoder.SetIndent("", " ")
|
||||
err = encoder.Encode(options)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
return buffer.String(), nil
|
||||
return wrapString(buffer.String()), nil
|
||||
}
|
||||
|
|
|
@ -50,8 +50,7 @@ type HTTPRequest interface {
|
|||
}
|
||||
|
||||
type HTTPResponse interface {
|
||||
GetContent() ([]byte, error)
|
||||
GetContentString() (string, error)
|
||||
GetContent() (*StringBox, error)
|
||||
WriteTo(path string) error
|
||||
}
|
||||
|
||||
|
@ -210,27 +209,22 @@ type httpResponse struct {
|
|||
}
|
||||
|
||||
func (h *httpResponse) errorString() string {
|
||||
content, err := h.GetContentString()
|
||||
content, err := h.GetContent()
|
||||
if err != nil {
|
||||
return fmt.Sprint("HTTP ", h.Status)
|
||||
}
|
||||
return fmt.Sprint("HTTP ", h.Status, ": ", content)
|
||||
}
|
||||
|
||||
func (h *httpResponse) GetContent() ([]byte, error) {
|
||||
func (h *httpResponse) GetContent() (*StringBox, error) {
|
||||
h.getContentOnce.Do(func() {
|
||||
defer h.Body.Close()
|
||||
h.content, h.contentError = io.ReadAll(h.Body)
|
||||
})
|
||||
return h.content, h.contentError
|
||||
}
|
||||
|
||||
func (h *httpResponse) GetContentString() (string, error) {
|
||||
content, err := h.GetContent()
|
||||
if err != nil {
|
||||
return "", err
|
||||
if h.contentError != nil {
|
||||
return nil, h.contentError
|
||||
}
|
||||
return string(content), nil
|
||||
return wrapString(string(h.content)), nil
|
||||
}
|
||||
|
||||
func (h *httpResponse) WriteTo(path string) error {
|
||||
|
|
12
experimental/libbox/panic.go
Normal file
12
experimental/libbox/panic.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package libbox
|
||||
|
||||
// https://github.com/golang/go/issues/46893
|
||||
// TODO: remove after `bulkBarrierPreWrite: unaligned arguments` fixed
|
||||
|
||||
type StringBox struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
func wrapString(value string) *StringBox {
|
||||
return &StringBox{Value: value}
|
||||
}
|
|
@ -13,12 +13,12 @@ func ClearServiceError() {
|
|||
os.Remove(serviceErrorPath())
|
||||
}
|
||||
|
||||
func ReadServiceError() (string, error) {
|
||||
func ReadServiceError() (*StringBox, error) {
|
||||
data, err := os.ReadFile(serviceErrorPath())
|
||||
if err == nil {
|
||||
os.Remove(serviceErrorPath())
|
||||
}
|
||||
return string(data), err
|
||||
return wrapString(string(data)), err
|
||||
}
|
||||
|
||||
func WriteServiceError(message string) error {
|
||||
|
|
Loading…
Reference in a new issue