Optimization method and device for memory overflow of springboard machine, equipment and medium

By introducing an observer monitoring mechanism into the TCP connection of the jump server, the problem of jump server memory overflow is solved, resource usage is optimized, server stability and performance are improved, business configuration is supported, and lightweight monitoring and fast response are achieved.

CN121907911APending Publication Date: 2026-04-21FUJIAN ZIXUN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511805510.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-03
Publication Date
2026-04-21

Smart Images

  • Figure CN121907911A_ABST
    Figure CN121907911A_ABST
Patent Text Reader

Abstract

The invention provides an optimization method and device for memory overflow of a springboard machine, equipment and a medium, the springboard machine comprises two TCP connections for parallel data copying, and the optimization method comprises the following steps: establishing an observer monitoring mechanism between the two TCP connections for parallel data copying; the observer monitors a data reading event of two TCP connections; when it is detected that connection of any end completes data transmission, the observer enters a warning state; and in the warning state, if the surviving TCP connection does not read the data within the preset timeout time, the observer actively closes the corresponding two TCP connections, and the idle connection is timely closed through a monitoring mechanism, so that the connection resource accumulation is prevented, the normal operation of the springboard machine on the server is ensured, and the user experience feeling is good.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer network technology, and in particular to an optimization method, apparatus, device, and medium for memory overflow of jump servers. Background Technology

[0002] A jump server (or jump box) is a relay server in a network security architecture that serves as the sole entry point for accessing internal network resources. It acts like a "secure bridge," requiring all management operations on internal servers to first log in to the jump server before being forwarded to the target server.

[0003] Existing cross-border e-commerce browsers use jump servers to alter the traffic flow and characteristics of user stores. Users establish a TCP connection with the jump server, which then establishes a TCP connection with a proxy server. The jump server forwards data between these two connections. The proxy capability of this jump server is implemented based on the sing-box library. The jump server is deployed on a server. However, during use, the server's memory usage has been continuously increasing, and memory release is extremely slow. When the number of users continues to increase, it can lead to server memory overflow, rendering the jump server unusable. Summary of the Invention

[0004] The technical problem to be solved by the present invention is to provide an optimization method, device, equipment and medium for memory overflow of jump servers, which closes idle connections in a timely manner through a monitoring mechanism to prevent the accumulation of connection resources, ensures the normal operation of jump servers on the server and improves the user experience.

[0005] In a first aspect, the present invention provides an optimization method for memory overflow in a jump server, wherein the jump server includes two TCP connections for parallel data copying, comprising the following steps: Step 1: Establish an observer monitoring mechanism between two TCP connections that are copying data in parallel; Step 2: The observer monitors the data read events of the two TCP connections; Step 3: When the observer detects that any connection has completed data transmission, it enters an alert state. In the alert state, if the surviving TCP connection does not read data within a preset timeout period, the observer actively closes the corresponding two TCP connections.

[0006] Secondly, the present invention provides an optimization device for memory overflow of a jump server, wherein the jump server includes two TCP connections for parallel data copying, and includes the following modules: Establish an observer module to create an observer monitoring mechanism between two TCP connections that are copying data in parallel; The monitoring connection module, wherein the observer monitors data read events of two TCP connections; The alert shutdown module activates an alert state when it detects that data transmission has been completed at any end of the connection. In this alert state, if the surviving TCP connection does not receive data within a preset timeout period, the observer actively closes the corresponding two TCP connections.

[0007] Thirdly, the present invention provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in the first aspect.

[0008] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.

[0009] One or more technical solutions provided by this invention have at least the following technical effects or advantages: 1. Resource optimization and leakage prevention Proactive connection management: Idle connections are closed in a timely manner through a monitoring mechanism to prevent the accumulation of connection resources; Memory leak protection: Ensure that thread and timer resources are released correctly; Efficient resource utilization: Avoid botnets consuming system resources and improve server capacity.

[0010] 2. Improved system stability Fault isolation: When a connection at one end is abnormally disconnected, the relevant connections can be quickly cleared to prevent impact on the overall stability of the system; Automatic recovery: Forcefully interrupts abnormal links to free up resources for new healthy connections; Preventing congestion: Avoiding the problem of the other end waiting indefinitely due to a disconnection at one end.

[0011] 3. Flexibility and configurability Configurable timeout: Supports adjusting the alert timeout threshold (such as 60 seconds or other values) according to business needs. Easy to integrate: It can be embedded into existing systems through a simple API interface.

[0012] 4. Performance advantages Lightweight monitoring: It uses channel communication and non-blocking operation, with minimal impact on system performance; Precise control: Strict monitoring is only activated when necessary (when one end is closed), reducing unnecessary performance overhead; Concurrency safety: Ensure that the monitoring thread is started only once to avoid race conditions.

[0013] 5. Enhanced reliability Dual protection mechanism: Under normal circumstances: relying on the connection's own closing mechanism; Abnormal situations: Forced intervention through observers; Real-time response: Through timer polling and signal reset mechanisms, it can quickly respond to changes in connection status; Comprehensive coverage: Simultaneous monitoring of bidirectional data streams ensures that all anomalies can be handled.

[0014] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it in accordance with the contents of the specification, and in order to make the above and other objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention are described below. Attached Figure Description

[0015] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0016] Figure 1 This is a flowchart of the method in Embodiment 1 of the present invention; Figure 2 This is a schematic diagram of the device in Embodiment 2 of the present invention. Detailed Implementation

[0017] The overall concept of the technical solution in this application is as follows: In two TCP connections performing parallel data copying (referred to as TCP connection-A and TCP connection-B), a third-party role, which can be called an "observer" or "monitor," is introduced. The observer's responsibility is to monitor data read events on these two connections. Once it detects that one end of the connection has completed data transmission (e.g., actively closed or encountered EOF), the observer enters a "standby state." In this state, if the remaining connection has not read any data for more than one minute (this duration is configurable), the observer will actively close both TCP connections, forcibly interrupting the entire data link to prevent the accumulation and waste of connection resources.

[0018] The following are the specific code implementation steps: 1. Observer Structure Definition and Initialization The observer is primarily responsible for timeout management and performs predefined termination operations (such as closing the connection) after a timeout.

[0019] go package bufio import ( "github.com / fanyiguang / brick / channel" "sync" "time" ) type Watcher struct { sync.Once finish func() / / Termination function to be executed after timeout timer chan struct{} done chan struct{} } / / Create a new observer instance func NewWatcher(f func()) *Watcher { return &Watcher{ timer: make(chan struct{}, 1), done: make(chan struct{}), finish: f, } } 2. The core logic of the observer The observer starts a timer using the Start method to periodically check for a reset signal. If no signal is received within the timeout period, a termination operation is performed.

[0020] go func (a *Watcher) Start(timeout int) { a.Do(func() { go a.start(timeout) }) } func (a *Watcher) start(timeout int) { ticker := time.NewTicker(time.Duration(timeout) * time.Second) defer ticker.Stop() / / The ticker must be stopped manually to prevent memory leaks. for { select { case <-ticker.C: / / Attempt to receive signals from the timer channel in a non-blocking manner _, err := channel.NonBlockAccept(a.timer) if err != nil { / / If reception fails (i.e., no reset signal is received), execute the termination function and exit. a.finish() return } case <- a.done: / / If a close signal is received, exit directly. return } } } / / Reset the observer's timeout timer func (a *Watcher) ResetTimer() { _ = channel.NonBlockSend(a.timer, struct{}{}) } / / Close the observer and release related resources func (a *Watcher) Close() { channel.Close(a.done) } Key points: The Start method uses sync.Once to ensure that the monitoring thread is started only once.

[0021] The timer ticker must be explicitly stopped by defer ticker.Stop() to avoid memory leaks.

[0022] The ResetTimer method is used to send a signal to the timer channel to reset the countdown for the alert state.

[0023] The Close method is used to notify observers to stop working and clean up related resources to prevent memory leaks.

[0024] 3. Integrate observers during data stream copying. When copying data streams between two connections, an observer instance is created and injected into the data reading and writing process.

[0025] go func CopyConnContextListEx(contextList []context.Context, sourcenet.Conn, destination net.Conn) error { var group task.Group / / Create an observer and set its timeout action to close both connections. watcher := NewWatcher(func() { _ = common.Close(source, destination) }) defer watcher.Close() / / Ensure the watcher is closed when the function exits to prevent memory leaks. / / Copy the upstream data stream (from source to destination) if _, dstDuplex := common.Cast[rw.WriteCloser](destination);dstDuplex { group.Append("upload", func(ctx context.Context) error { err := common.Error(CopyEx(destination, source, watcher)) if err == nil { rw.CloseWrite(destination) } else { common.Close(destination) } / / Upstream transmission complete, start the observer to enter alert mode (timeout set to 60 seconds). watcher.Start(60) return err }) } / / Downlink data stream copy (from destination to source) if _, srcDuplex := common.Cast[rw.WriteCloser](source); srcDuplex{ group.Append("download", func(ctx context.Context) error { err := common.Error(CopyEx(source, destination, watcher)) if err == nil { rw.CloseWrite(source) } else { common.Close(source) } / / Downlink transmission complete, start the observer to enter alert mode (timeout set to 60 seconds). watcher.Start(60) return err }) } group.Cleanup(func() { common.Close(source, destination) }) return group.RunContextList(contextList) } Integrated logic description: Before starting the bidirectional data stream copy, create an observer instance and define its timeout callback to close both connections.

[0026] By using `defer`, we ensure that `watcher.Close()` is called when the function exits, thus preventing memory leaks in the observer itself.

[0027] Start copy tasks in the up and down directions respectively, and call watcher.Start(60) at the end of the copy task in each direction to put the observer into a watchful state.

[0028] In alert mode, if no data is read from the surviving connection within 60 seconds, the observer will forcibly close both connections.

[0029] 4. Reset the observer timer during data reading. In the specific copy logic (CopyEx method), after each successful read from the connection, watcher.ResetTimer() must be called to reset the observer's watch timer countdown.

[0030] go for { err = source.ReadBuffer(buffer) if err != nil { buffer.Release() if errors.Is(err, io.EOF) { err = nil return } return } dataLen := buffer.Len() if dataLen > 0 { / / Reset the observer's vigilance countdown each time data is read. watcher.ResetTimer() } buffer.OverCap(rearHeadroom) err = destination.WriteBuffer(buffer) if err != nil { buffer.Leak() if !notFirstTime { err = N.ReportHandshakeFailure(originSource, err) } return } } Reset logic explanation: When reading data from the source connection in a loop, the watcher.ResetTimer() method is called as soon as valid data (dataLen>0) is read.

[0031] This method sends a signal to the observer's timer channel, causing it to reset its internal timeout timer.

[0032] The purpose of this design is to prevent the observer from mistakenly judging a timeout when one end of the connection has ended transmission while the other end is still continuously reading data, by constantly resetting the timer. The observer will only forcibly close the connection if the surviving connection has not read data for an extended period (exceeding a set threshold).

[0033] Through the steps described above, we introduced an observer mechanism into two TCP connections that copy data in parallel. This mechanism can monitor the data reading activity of the other connection after one connection terminates transmission prematurely. If no data is read from the surviving connection within a configurable time, the observer will proactively close both connections, preventing the unnecessary occupation and accumulation of connection resources. The entire implementation emphasizes resource management, effectively avoiding memory leaks by closing the observer and timer in a timely manner. Example

[0034] like Figure 1 As shown, this embodiment provides an optimization method for memory overflow in a jump server, wherein the jump server includes two TCP connections for parallel data copying, and includes the following steps: Step 1: Establish an observer monitoring mechanism between two TCP connections that are copying data in parallel; Step 2: The observer monitors the data read events of the two TCP connections; Step 3: When the observer detects that any connection has completed data transmission, it enters an alert state. In the alert state, if the surviving TCP connection does not read data within a preset timeout period, the observer actively closes the corresponding two TCP connections.

[0035] In this embodiment, preferably, the establishment of the observer monitoring mechanism specifically includes: Create an observer instance, which contains: The timer channel is used to receive reset signals; The completion channel is used to receive the shutdown signal; The termination function is used to define the close operation after a timeout, which means closing both TCP connections; Start a monitoring thread and periodically check the reset signal using a timer.

[0036] In this embodiment, preferably, the monitoring thread includes: Create a timer with a configurable duration; Listen to two channels in a loop: When a timer signal is received, attempt to receive the reset signal in a non-blocking manner; If receiving the reset signal fails, the termination function will be executed and the process will exit. When a shutdown signal is received, the program will exit immediately.

[0037] In this embodiment, preferably, the method further includes a reset mechanism: During the data copying process, a reset signal is sent to the timer channel in a non-blocking manner each time data is successfully read from the TCP connection. The reset signal is used to reset the observer's timeout timer; It also includes a resource release mechanism: Send a close signal to the completion channel; Stop the monitoring thread; Release relevant channel resources.

[0038] Based on the same inventive concept, this application also provides an apparatus corresponding to the method in Embodiment 1, as detailed in Embodiment 2.

[0039] Example 2 like Figure 2 As shown, this embodiment provides an optimization device for bastion host memory overflow, wherein the bastion host includes two parallel data copying TCP connections, and includes the following modules: Establish an observer module to create an observer monitoring mechanism between two TCP connections that are copying data in parallel; The monitoring connection module, wherein the observer monitors data read events of two TCP connections; The alert shutdown module activates an alert state when it detects that data transmission has been completed at any end of the connection. In this alert state, if the surviving TCP connection does not receive data within a preset timeout period, the observer actively closes the corresponding two TCP connections.

[0040] In this embodiment, preferably, the establishment of the observer monitoring mechanism specifically includes: Create an observer instance, which contains: The timer channel is used to receive reset signals; The completion channel is used to receive the shutdown signal; The termination function is used to define the close operation after a timeout, which means closing both TCP connections; Start a monitoring thread and periodically check the reset signal using a timer.

[0041] In this embodiment, preferably, the monitoring thread includes: Create a timer with a configurable duration; Listen to two channels in a loop: When a timer signal is received, attempt to receive the reset signal in a non-blocking manner; If receiving the reset signal fails, the termination function will be executed and the process will exit. When a shutdown signal is received, the program will exit immediately.

[0042] In this embodiment, preferably, a reset mechanism is also included: During the data copying process, a reset signal is sent to the timer channel in a non-blocking manner each time data is successfully read from the TCP connection. The reset signal is used to reset the observer's timeout timer; It also includes a resource release mechanism: Send a close signal to the completion channel; Stop the monitoring thread; Release relevant channel resources.

[0043] Since the apparatus described in Embodiment 2 of the present invention is an apparatus used to implement the method of Embodiment 1 of the present invention, those skilled in the art can understand the specific structure and variations of the apparatus based on the method described in Embodiment 1 of the present invention, and therefore will not be described again here. All apparatuses used in the method of Embodiment 1 of the present invention fall within the scope of protection of the present invention.

[0044] Based on the same inventive concept, this application provides an electronic device embodiment corresponding to Embodiment 1, as detailed in Embodiment 3.

[0045] Example 3 This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it can implement any of the implementation methods in Embodiment 1.

[0046] Since the electronic device described in this embodiment is the device used to implement the method in Embodiment 1 of this application, those skilled in the art can understand the specific implementation method and various variations of the electronic device in this embodiment based on the method described in Embodiment 1 of this application. Therefore, how the electronic device implements the method in the embodiment of this application will not be described in detail here. Any device used by those skilled in the art to implement the method in the embodiment of this application falls within the scope of protection of this application.

[0047] Based on the same inventive concept, this application provides a storage medium corresponding to Embodiment 1, as detailed in Embodiment 4.

[0048] Example 4 This embodiment provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it can implement any of the implementation methods in Embodiment 1.

[0049] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0050] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0051] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0052] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0053] While specific embodiments of the present invention have been described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and not intended to limit the scope of the present invention. Equivalent modifications and variations made by those skilled in the art in accordance with the spirit of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. An optimization method for memory overflow in a jump server, wherein the jump server includes two TCP connections for parallel data copying, characterized in that: Includes the following steps: Step 1: Establish an observer monitoring mechanism between two TCP connections that are copying data in parallel; Step 2: The observer monitors the data read events of the two TCP connections; Step 3: When the observer detects that any connection has completed data transmission, it enters an alert state. In the alert state, if the surviving TCP connection does not read data within a preset timeout period, the observer actively closes the corresponding two TCP connections.

2. The method according to claim 1, characterized in that, The establishment of the observer monitoring mechanism specifically includes: Create an observer instance, which contains: The timer channel is used to receive reset signals; The completion channel is used to receive the shutdown signal; The termination function is used to define the close operation after a timeout, which means closing both TCP connections; Start a monitoring thread and periodically check the reset signal using a timer.

3. The method according to claim 2, characterized in that, The monitoring threads include: Create a timer with a configurable duration; Listen to two channels in a loop: When a timer signal is received, attempt to receive the reset signal in a non-blocking manner; If receiving the reset signal fails, the termination function will be executed and the process will exit. When a shutdown signal is received, the program will exit immediately.

4. The method according to claim 1, characterized in that, The method also includes a reset mechanism: During the data copying process, a reset signal is sent to the timer channel in a non-blocking manner each time data is successfully read from the TCP connection. The reset signal is used to reset the observer's timeout timer; It also includes a resource release mechanism: Send a close signal to the completion channel; Stop the monitoring thread; Release relevant channel resources.

5. An optimization device for memory overflow in a jump server, wherein the jump server includes two TCP connections for parallel data copying, characterized in that: Includes the following modules: Establish an observer module to create an observer monitoring mechanism between two TCP connections that are copying data in parallel; The monitoring connection module, wherein the observer monitors data read events of two TCP connections; The alert shutdown module activates the observer's alert state when it detects that data transmission has been completed at either end. In the alert state, if the surviving TCP connection does not read data within a preset timeout period, the observer will actively close the corresponding two TCP connections.

6. The apparatus according to claim 5, characterized in that: The establishment of the observer monitoring mechanism specifically includes: Create an observer instance, which contains: The timer channel is used to receive reset signals; The completion channel is used to receive the shutdown signal; The termination function is used to define the close operation after a timeout, which means closing both TCP connections; Start a monitoring thread and periodically check the reset signal using a timer.

7. The apparatus according to claim 6, characterized in that: The monitoring threads include: Create a timer with a configurable duration; Listen to two channels in a loop: When a timer signal is received, attempt to receive the reset signal in a non-blocking manner; If receiving the reset signal fails, the termination function will be executed and the process will exit. When a shutdown signal is received, the program will exit immediately.

8. The apparatus according to claim 5, characterized in that: It also includes a reset mechanism: During the data copying process, a reset signal is sent to the timer channel in a non-blocking manner each time data is successfully read from the TCP connection. The reset signal is used to reset the observer's timeout timer; It also includes a resource release mechanism: Send a close signal to the completion channel; Stop the monitoring thread; Release relevant channel resources.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1 to 4.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1 to 4.