-
Notifications
You must be signed in to change notification settings - Fork 802
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
[SCB-687] add highway server connection protection #824
Conversation
@@ -57,8 +69,18 @@ public void init(Vertx vertx, String sslKey, AsyncResultCallback<InetSocketAddre | |||
} | |||
|
|||
netServer.connectHandler(netSocket -> { | |||
TcpServerConnection connection = createTcpServerConnection(); | |||
connection.init(netSocket); | |||
if (connectedCounter.get() < connectionLimit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems this is more clear.
if (connectedCounter.incrementAndGet() > connectionLimit){
connectedCounter.decrementAndGet();
netSocket.close();
return;
}
TcpServerConnection connection = createTcpServerConnection();
connection.init(netSocket, connectedCounter);
EventManager.post(new ClientConnectedEvent(netSocket, connectedCount));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
import io.vertx.core.Vertx; | ||
import io.vertx.core.net.NetServer; | ||
import io.vertx.core.net.NetServerOptions; | ||
|
||
public class TcpServer { | ||
private URIEndpointObject endpointObject; | ||
|
||
private final AtomicInteger connectedCounter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TcpServer will be created for each HighwayServerVerticle instance
so the counter number in server is not correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your means I need move it to HighwayServerVerticle instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we only deploy one HighwayServerVerticle instance (as a spring bean), so may not problem ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if serivcecomb.highway.thread-count is n, then HighwayServerVerticle instance count is n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, forgotten
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
log4j.rootLogger=INFO, stdout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new projects switch to logback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may do it in https://issues.apache.org/jira/browse/SCB-683 later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already depend on pojo-test jar, can remove this file
highway: | ||
address: 0.0.0.0:7070 | ||
server: | ||
connection-limit: 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider dynamic update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is not necessary yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discuss with customers, we should support this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already depend on pojo-test jar
and you want to reuse it's declare
so only need to append new config items, no need to declare everything again.
return counters; | ||
} | ||
|
||
@Subscribe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all eventloop thread will sync invoke this
it's not a good sample.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this watcher purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only for test
Assert.assertArrayEquals("check connection count change", new Integer[] {1, 0}, watcher.getCounters().toArray());
watcher will receive a connection connected event when consumer calling
event.getTotalConnectedCount() = 1
and when
SCBEngine.getInstance().destroy();
watcher will receive a connection close event
event.getTotalConnectedCount() = 0
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
…pdate Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
@@ -17,6 +17,9 @@ | |||
|
|||
package org.apache.servicecomb.foundation.vertx; | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is one space?
also need to check other codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copy before, and I am using GoogleStyle in etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, i made a mistake caused by the char "+"
@@ -17,7 +17,7 @@ | |||
|
|||
APPLICATION_ID: pojotest-it | |||
service_description: | |||
name: pojo-connection-limit | |||
name: pojo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conflict with integration-tests/pojo-test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think no problem,also reused
PojoService.hello.SayHello("whatever");
in pojo-test but need add servicecomb.highway.server.onnection-limit
setting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at last, we will move integration test to real SC, not a mock SC, your logic will cause conflict in that time.
public class PojoSpringMain { | ||
|
||
public static void main(final String[] args) { | ||
SpringApplication.run(PojoSpringMain.class, args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already depend on pojo-test jar
just invoke org.apache.servicecomb.demo.pojo.test.PojoTestMain
no need to depend on complex springboot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
Follow this checklist to help us incorporate your contribution quickly and easily:
[SCB-XXX] Fixes bug in ApproximateQuantiles
, where you replaceSCB-XXX
with the appropriate JIRA issue.mvn clean install
to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.Add
servicecomb.highway.server.connection-limit
for setting this limitDefault value is Integer.MAX_VALUE
eclipse-vertx/vert.x#2542