Skip to content

Commit 1be4c6a

Browse files
author
Greg Meyer
authored
Merge pull request #7 from DirectProjectJavaRI/develop
Releasing 8.0.1
2 parents b8b4ba4 + 2f5e28c commit 1be4c6a

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<artifactId>dns</artifactId>
66
<name>Direct Project DNS services</name>
7-
<version>8.0.0</version>
7+
<version>8.0.1</version>
88
<description>Direct Project DNS services</description>
99
<inceptionYear>2010</inceptionYear>
1010
<url>https://github.com/DirectProjectJavaRI/dns</url>

src/main/java/org/nhindirect/dns/DNSServerSettings.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ public class DNSServerSettings extends SocketServerSettings
3232
private static final int DEFAULT_PORT = 53;
3333
private static final String DEFAULT_BIND_ADDRESS = "0.0.0.0"; // bind to all adapters
3434
public static final int DAFAULT_MAX_REQUEST_SIZE = 1024 * 16;
35+
public static final int DAFAULT_MAX_RECONNECT_ATTEMPTS = 10;
36+
3537

3638
private int port;
3739
private String bindAddress;
3840
private int maxRequestSize;
41+
private int maxReconnectAttempts;
3942

4043
/**
4144
* Create default DNS server settings
@@ -46,6 +49,7 @@ public DNSServerSettings()
4649
port = DEFAULT_PORT;
4750
bindAddress = DEFAULT_BIND_ADDRESS;
4851
maxRequestSize = DAFAULT_MAX_REQUEST_SIZE;
52+
maxReconnectAttempts = DAFAULT_MAX_RECONNECT_ATTEMPTS;
4953
}
5054

5155
/**
@@ -103,4 +107,26 @@ public void setMaxRequestSize(int maxRequestSize)
103107
{
104108
this.maxRequestSize = maxRequestSize;
105109
}
110+
/**
111+
* Gets the maximum number of times the service will attempt to reconnect
112+
* to the underlying IP stack if association is lost.
113+
*
114+
* @return The maximum number of times the service will attempt to reconnect
115+
* to the underlying IP stack
116+
*/
117+
public int getMaxReconnectAttempts()
118+
{
119+
return maxReconnectAttempts;
120+
}
121+
122+
/**
123+
* Sets the maximum number of times the service will attempt to reconnect
124+
* to the underlying IP stack if association is lost.
125+
* @param maxReconnectAttempts the maximum number of times the service will attempt to reconnect
126+
* to the underlying IP stack
127+
*/
128+
public void setMaxReconnectAttempts(int maxReconnectAttempts)
129+
{
130+
this.maxReconnectAttempts = maxReconnectAttempts;
131+
}
106132
}

src/main/java/org/nhindirect/dns/TCPServer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ private void reconnect()
167167
serverSocket.close();
168168
} catch (IOException e) {/* no-op */}
169169

170+
int numAttempts = 0;
170171
serverSocket = null;
171172
while (serverSocket == null && running.get())
172173
{
@@ -177,6 +178,13 @@ private void reconnect()
177178
}
178179
catch (DNSException ex)
179180
{
181+
++numAttempts;
182+
if (numAttempts > settings.getMaxReconnectAttempts())
183+
{
184+
log.error("Maximum number of TCP rebinds has been exceeded. The DNS server will terminate");
185+
System.exit(-1);
186+
}
187+
180188
log.error("DNS TCP server socket failed to rebind. Trying again in 5 seconds.");
181189

182190
// the socket creation failed....

src/main/java/org/nhindirect/dns/UDPServer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ private void reconnect()
166166
// socket may already be closed, but clean up to be thorough.
167167
serverSock.close();
168168

169+
int numAttempts = 0;
169170
serverSock = null;
170171
while (serverSock == null && running.get())
171172
{
@@ -176,6 +177,13 @@ private void reconnect()
176177
}
177178
catch (DNSException ex)
178179
{
180+
++numAttempts;
181+
if (numAttempts > settings.getMaxReconnectAttempts())
182+
{
183+
log.error("Maximum number of UDP rebinds has been exceeded. The DNS server will terminate");
184+
System.exit(-1);
185+
}
186+
179187
log.error("DNS UDP server socket failed to rebind. Trying again in 5 seconds.");
180188

181189
// the socket creation failed....

src/main/java/org/nhindirect/dns/springconfig/DNSServerConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ public class DNSServerConfig
1616
@Value("${direct.dns.binding.address:0.0.0.0}")
1717
protected String bindAddress;
1818

19+
@Value("${direct.dns.binding.maxReconnectAttempts:10}")
20+
protected int maxReconnectAttempts;
21+
1922
@Bean
2023
@ConditionalOnMissingBean
2124
public DNSServerSettings dnsServerSettings()
2225
{
2326
final DNSServerSettings settings = new DNSServerSettings();
2427
settings.setBindAddress(bindAddress);
2528
settings.setPort(port);
29+
settings.setMaxReconnectAttempts(maxReconnectAttempts);
2630

2731
return settings;
2832
}

0 commit comments

Comments
 (0)